Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Latex Table of Contents Links to Wrong Section

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.

like image 206
Verhogen Avatar asked Apr 23 '09 15:04

Verhogen


2 Answers

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.

like image 135
Noah Avatar answered Oct 14 '22 11:10

Noah


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.

like image 45
Paul Biggar Avatar answered Oct 14 '22 10:10

Paul Biggar