2
votes

i have a simple tex file. when i compile it with $ pdflatex test.tex it generates a pdf. the table of contents has clickable links but they don't work! the page numbering is correct, but when i click a line it directs me to the wrong page.

has anyone an idea how i can fix it?

here is my code:

\documentclass[12pt,titlepage]{scrartcl}

\usepackage[nottoc,numbib]{tocbibind}
\usepackage{graphicx}
\usepackage[section]{placeins}
\usepackage{float}
\usepackage{amsmath}
\usepackage[autostyle=false,german=quotes]{csquotes}  %% for \enquote{}
\usepackage[ngerman]{babel}
\usepackage[utf8]{inputenc}
\usepackage{listings}
\usepackage[]{hyperref}
\title{test}
\author{me}
\date{\today}

\begin{document}
\pagenumbering{roman}
\begin{titlepage}
\maketitle
\end{titlepage}
\setcounter{section}{-1}
\section[]{Abstract}
blabla bla
\newpage
\tableofcontents
\newpage
\pagenumbering{arabic}
\part{part1}
\setcounter{section}{-1}
\section[]{Abstract}
\section{sec a 1}
bla bla
\subsection{sec a 1.1}
bla blub
\section{sec a 2}
\newpage
\part{part2}
\setcounter{section}{-1}
\section[]{Abstract}
\section{sec b 1} % the toc entry for this section points to page 1 but it is on page 2
blub blub
\section{sec b 2}  % the toc entry for this section points to page 1 but it is on page 2
blub blub
\subsection{sec b 2.1} % the subsection in the toc points to the right 2nd page!

\end{document}

and here you see the toc. as you can see, the mouse over hint tells that the link points to page 1 but the number on the right says it is on page 2.

wrong link

thanks in advance.

1

1 Answers

3
votes

Whenever you reuse a hyperref counter that could make its way into a link, duplicate hyperlinks occur. Visually this is fine, but internal to the document, the jumps are ambiguous. So, you need to provide hyperref some help.

The easiest way to circumvent this problem and provide hyperref some assistance is to add to your preamble

\renewcommand{\theHsection}{\thepart.section.\thesection}

after loading hyperref. The above prepends \thepart. to the hyperref-related \section link. Since the re-use of \section counters is based on your use of \parts, this addition will make for a unique link and remove ambiguous destinations.