2

I use hyperref for my entries in the TOC to be link.

But with the example below, I have a problem:

\item{\textbf{item one}\addcontentsline{toc}{subsection}{item one}\\
    Lots of text...
}

\newpage

\item{\textbf{item two}\addcontentsline{toc}{subsection}{item two}\\
    Lots of text...
}

The problem is the link to item two link to the page just before item two (so just before the \newpage) instead of item two.

I also tried without the \newpage but it make the same mistake if the first line of the item two is on the next page.

The strange fact is that the page number in the TOC is right but the link isn't...

  • 1
    Your are missing \phantomsection right before \addcontentsline. Do you really want to write \item content to the TOC? – user31729 Jul 16 '14 at 14:26
  • Yes I really want to put my items (just a title for each item like in the example I gave) in the TOC and thanks a lot for your answer, it works well. :) (What should I do to say your comment is the answer of my question?) – Matthieu.P Jul 16 '14 at 14:46
  • 1
    @Matthieu.P Wait until Christian writes something and accept it. If he doesn't, you may answer it by yourself or if you think, no one will need this information later on, you can just delete your post. – LaRiFaRi Jul 16 '14 at 14:53
5

As stated in the hyperref manual, for example here, ftp://ftp.rrzn.uni-hannover.de/pub/mirror/tex-archive/macros/latex/contrib/hyperref/doc/manual.html#x1-190005,

a \phantomsection command is needed right before \addcontentsline to guarantee correct linking.

\phantomsection  
\item{\textbf{item two}\addcontentsline{toc}{subsection}{item two}\\
    Lots of text...
}

This is a small document:

\documentclass{article}
\usepackage{blindtext}
\usepackage{hyperref}
\begin{document}
\tableofcontents

\clearpage

\begin{itemize}


\item{\textbf{item one}\phantomsection
    \addcontentsline{toc}{subsection}{item one}\\
    \blindtext
}

\newpage
\item{\textbf{item two}\phantomsection
\addcontentsline{toc}{subsection}{item two}\\
    \blindtext
}

\end{itemize}

\end{document}

Since no further information is given on the code, there are some guesses about the class, the itemize environment etc.

I omitted a screen shot, since it does not reveal a very sophisticated output.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.