4

I use the hyperref package. However, the link in the table of content (toc) of "List of figures" (lof) leads to the toc instead of the lof. I have the \addcontentsline command before \listoffigures. Swapping them, I get the correct link but wrong page numbers in the toc. It seem to be only a problem if the lof is longer than one page. Does anybody how to get both the link and the number right?

Here is a minimum working example.

\documentclass[10pt]{article}

\usepackage{graphicx}
\usepackage{lipsum,forloop}
\usepackage[]{hyperref}

\begin{document}
    \tableofcontents
    \clearpage
    \addcontentsline{toc}{section}{List of figures}
    \listoffigures

    \newcounter{ct}
    \forloop{ct}{1}{\value{ct} < 25}%
    {   
    \clearpage
    \section{Another section}

    \lipsum[1]
    \begin{figure}[htb]
        \centering
        \includegraphics[width=0.2\linewidth]{example-image}
        \caption{Example}
    \end{figure}

    \subsection{Another subsection}

    \lipsum[1]
    \begin{figure}[htb]
        \centering
        \includegraphics[width=0.2\linewidth]{example-image}
        \caption{Example}
    \end{figure}
    }   
\end{document}
JK19
  • 113
  • 2
    workaround: remove \addcontentsline and add \usepackage{tocbibind}. – Marijn Oct 02 '17 at 09:57
  • 2
    Nothing wrong with tocbibind, but for a general way to tell hyperref where to jump, look at https://tex.stackexchange.com/questions/44088/when-do-i-need-to-invoke-phantomsection – Michael Palmer Oct 02 '17 at 17:46
  • @JK19 if you have found a solution please provide an answer with a mwe. –  Oct 02 '17 at 22:04
  • Sorry for the late response. I omitted \addcontents line and added \usepackage[nottoc]{tocbibind} – JK19 Nov 03 '17 at 14:49
  • 4
    I'm voting to close this question as off-topic because it could be solved in comments –  Dec 28 '17 at 22:56
  • "off topic" for a very useful question that later users have, instead of making an answer summarizing the comments. Classic StackExchange... – Caleb Stanford Jul 05 '22 at 18:55

0 Answers0