25

I have a section followed by a table of contents like so:

\section{Section1}
ABC.

\addcontentsline{toc}{section}{Table of Contents}
\tableofcontents
\newpage
\addcontentsline{toc}{section}{List of Figures}
\listoffigures
\newpage

\section{Section2}
DEF.
\section{Section3}
GHI.

My issue is that the "Table of Contents" and "List of Figures" entries in the table of contents link (in the generated pdf) to the wrong place in the file. They both link to the first section section on page 1. The entry in the table is correct (TOC says page 2 and LOF says page 3), but the link goes to the wrong place.

Verhogen
  • 27,221
  • 34
  • 90
  • 109

3 Answers3

34

You'll need to use the \phantomsection command:

\section{Section1}
ABC.
\phantomsection
\addcontentsline{toc}{section}{Table of Contents}
\tableofcontents
\newpage
\phantomsection
\addcontentsline{toc}{section}{List of Figures}
\listoffigures
\newpage

\section{Section2}
DEF.
\section{Section3}
GHI.

See the hyperref manual.

Noah
  • 21,451
  • 8
  • 63
  • 71
2

If you're doing this for the bibliography, list of tables or list of figures,

\usepackage[nottoc]{tocbibind}

should fix it, without the wrong-page problems. Otherwise, I havent come across a better solution than \phantomsection with \addcontentsline.

Paul Biggar
  • 27,579
  • 21
  • 99
  • 152
0

This behavior is due to the fact that \tableofcontents inserts a page break before writing the contents. Hence, your PDF bookmark will point to the page before. Depending on your document class, you can manually insert a number of \newpage commands to keep \tableofcontents from adding another. One or two should be sufficient.

I know, it is a hacky solution, and there might exist a package to solve the problem, but this is how I work around the problem.

Tormod Fjeldskår
  • 5,952
  • 1
  • 29
  • 47
  • 2
    That didn't work, I added 1-3 new pages and it still links to the beginning of the previous section. I did the compile twice. – Verhogen Apr 24 '09 at 14:44