1

I want to add the table of contents to the bookmarks to facilitate navigation in the pdf. I managed to do so but the behaviour of said bookmark is inconsistant with the others as it anchors below the title of the toc and not directly to it (i.e. The "Contents" title is masked, only displaying the actual content of the ToC).

Any way to fix that?

MWE

\documentclass{article}
\usepackage{mwe}
\usepackage{bookmark}
\addtocontents{toc}{\protect{\pdfbookmark[section]{\contentsname}{toc}}}
\begin{document}
\tableofcontents
\blinddocument
\end{document}
  • 1
    Is \usepackage{tocbibind} working for you instead of using \addtocontents? – user31729 Sep 21 '17 at 9:19
  • @ChristianHupfer It does indeed work but it also adds a line for Contents in the ToC which I would like to avoid. – Florian Sep 21 '17 at 9:43
2

This inserts the bookmark and the relevant hypertarget such that it jumps to Contents, i.e. the heading of the Contents page.

\documentclass{article}
\usepackage{mwe}
\usepackage{bookmark}
\begin{document}
\pdfbookmark[section]{\contentsname}{toc}
\tableofcontents
\blinddocument
\end{document}

Another solution: Use etoolbox and \preto in order to prepend code to \tableofcontents.

\documentclass{article}
\usepackage{mwe}
\usepackage{etoolbox}
\usepackage{bookmark}

\preto{\tableofcontents}{\pdfbookmark[section]{\contentsname}{toc}}
\begin{document}
\tableofcontents
\blinddocument
\end{document}
  • It does work as intended, but it requires the statement to be passed after the beginning of the document which I would prefer to avoid. I am trying to develop a framework for documents which I include in the preamble. Any way to circumvent that? – Florian Sep 21 '17 at 9:52
  • @Florian: Did you specify that in your question? ;-) No, you didn't. – user31729 Sep 21 '17 at 9:54
  • Yes, your answer is correct as I stated. I was just wondering if you knew another way. – Florian Sep 21 '17 at 9:56
  • 1
    @Florian: See the edit – user31729 Sep 21 '17 at 9:59
  • Thank you so much. I had similar issues with other commands and this is going to solve a lot them. – Florian Sep 21 '17 at 11:16

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.