MakeIndex, Nomenclature, Glossaries and AcronymsProblem with TOC

Information and discussion about MakeIndex - the tool to generate subject indices for LaTeX documents.
Post Reply
Jongomez
Posts: 48
Joined: Tue Nov 28, 2023 9:29 pm

Problem with TOC

Post by Jongomez »

Good morning,
At the end of my Overleaf Latex document I have the following coding lines:

Code: Select all

\markright{\MakeUppercase{Bibliografía}}
\include{sections.tex/Bibliografía}

\addcontentsline{toc}{chapter}{Bibliografía}
\clearpage

\markright{\MakeUppercase{Índice de términos}}
\index{Índice de términos}
\addcontentsline{toc}{chapter}{Índice de términos}


\clearpage
\index{Índice de nombres}
\addcontentsline{toc}{chapter}{Índice de nombres}
\markright{\MakeUppercase{Índice de nombres}}

\printindex
PROBLEM: On the TOC: when clicking either entry: "Índice de términos" or "Índice de nombres" it sends me to "Bibliografía", instead to the right entry.

Can anyone help me on this problem?

Thanks a lot
Last edited by Stefan Kottwitz on Wed Dec 20, 2023 3:20 pm, edited 1 time in total.
Reason: code marked

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org
LaTeX Beginner's Guide LaTeX Cookbook LaTeX TikZ graphics TikZによるLaTeXグラフィックス
User avatar
Stefan Kottwitz
Site Admin
Posts: 10290
Joined: Mon Mar 10, 2008 9:44 pm

Problem with TOC

Post by Stefan Kottwitz »

Hi Jon,

put the \phantomsection command immediately before the \addcontentsline command, to create an anchor for the hyperref link.

Stefan

PS: it would be great if you would use the "Code" button when writing code in a post, instead of "**************************************************************************" before and after. Code is automatically highlighted and works with the online compiler here in the forum, which is especially beneficial for small compilable examples. I did it for you above.
LaTeX.org admin
Jongomez
Posts: 48
Joined: Tue Nov 28, 2023 9:29 pm

Problem with TOC

Post by Jongomez »

Hi Stefan,
You are great! It is very grateful to work with persons like you.
Your proposal has worked with "Índice de términos", but clicking on "Índice de nombres" on TOC entries it sends mi to "Índice de términos". What can be the cause?

Note.- I think I did something wrong with the code button: I've highlited the code lines below, but I haven't got the appropriate result. Would you let me know where is my error?
Thansk a lot.

Code: Select all

\markright{\MakeUppercase{Índice de términos}}
\index{Índice de términos}
\phantomsection
\addcontentsline{toc}{chapter}{Índice de términos}

\markright{\MakeUppercase{Índice de nombres}}
\index{Índice de nombres}
\phantomsection
\addcontentsline{toc}{chapter}{Índice de nombres}
Jongomez
Posts: 48
Joined: Tue Nov 28, 2023 9:29 pm

Problem with TOC

Post by Jongomez »

Sorry Steffan, I've realised that the code button works properly.
I hope you can help me with my last question.

Bet regards,
Jon
Jongomez
Posts: 48
Joined: Tue Nov 28, 2023 9:29 pm

Problem with TOC

Post by Jongomez »

Hi Steffan,
I think I got it finally.

This is the coding that works ok:

Code: Select all

\markright{\MakeUppercase{Índice de términos}}

\cleardoublepage
\phantomsection
\addcontentsline{toc}{chapter}{Índice de términos}
\index{Índice de términos}
\printindex

\cleardoublepage
\phantomsection

\addcontentsline{toc}{chapter}{Índice de nombres}
\markright{\MakeUppercase{Índice de nombres}}
\index{Índice de nombres}
Please let me know your opinion

Thanks so much for your help.
User avatar
Stefan Kottwitz
Site Admin
Posts: 10290
Joined: Mon Mar 10, 2008 9:44 pm

Problem with TOC

Post by Stefan Kottwitz »

Looks good! Specifically, the \cleardoublepage before both \phantomsection and the next chapter so you ensure that the anchor is on the new chapter's first page. Otherwise, the anchor would be on the current page, then you start a chapter that begins on another page, so the anchor/link would be wrong.

Stefan
LaTeX.org admin
Jongomez
Posts: 48
Joined: Tue Nov 28, 2023 9:29 pm

Problem with TOC

Post by Jongomez »

Hi Steffan,
It is always a pleasure hearing your opinions and recommendations.

thanks again,
Jon
Post Reply