# Contents in PDF bookmarks

I am using KOMA-Script (scrreprt) and hyperref.

(Also list of figures and list of tables if I include them)

What is the best way to do this?

I could add a \pdfbookmark manually but I'm not sure how to get it to point correctly to the start of the section - if I do it after it will be on the wrong page (multipage toc), if I do before it will be the page before (since \tableofcontents does \cleardoublepage?). I guess I have to redefine \tableofcontents somehow.

The following code should create a correct ToC bookmark for both scrreprt and scrbook:

\makeatletter
\usepackage{etoolbox}
\pretocmd{\tableofcontents}{%
\if@openright\cleardoublepage\else\clearpage\fi
\pdfbookmark[0]{\contentsname}{toc}%
}{}{}%
\makeatother

• For the lists of figures and tables, the above code should work by replacing \tableofcontents with \listoffigures resp. \listoftables, \contentsname with \listfigurename resp. \listtablename, toc with lof resp. lot. – lockstep Aug 16 '10 at 11:28

A general way for base classes using \addtocontents would be:

\addtocontents{toc}{\protect{\pdfbookmark[0]{\contentsname}{toc}}}


Similar for lof and lot with \listfigurename and \listtablename.

But, since KOMA-Script uses tocbasic, this would be better way and very simple:

\BeforeTOCHead[toc]{{\pdfbookmark[0]{\contentsname}{toc}}}


Here's a compilable example, where \BeforeTOCHead is used to create bookmarks for all such lists like toc, lof and lot.

\documentclass{scrbook}
\usepackage{hyperref}
\makeatletter
\cleardoublepage
\edef\@tempa{%
\noexpand\pdfbookmark[0]{\list@fname}{\@currext}%
}\@tempa
}
\makeatother
\begin{document}
\tableofcontents
\listoffigures
\listoftables
\chapter{One}
text
\end{document}


No redefinition of \tableofcontents and no etoolbox would be required. Different names by babel are supported.

• I tried \BeforeTOCHead[toc]{{\pdfbookmark[0]{\contentsname}{toc}}} but the bookmark seems to link to the blank left hand page before to toc (which starts on right hand side) – robince Aug 16 '10 at 12:48
• Oh never mind \BeforeTOCHead[toc]{{\cleardoublepage\pdfbookmark[0]{\contentsname}{toc}}} seems to do it. Thanks very much – robince Aug 16 '10 at 12:50
• Hmm, the code for all bookmarks doesn't work with the listings package, it points to the right page but the bookmark's name is empty. – letmaik Jan 6 '13 at 17:44
• @Anton: Did you load babel, as in e.g. \usepackage[ngerman]{babel}? – dpprdan Dec 17 '13 at 22:10
• @Anton: Sorry, then I guess you will have to post a new question with a MWE, because I cannot reproduce your problem with Stefan's example. Let us know here if you do, please. You might also want to check the order of your commands in the preamble, i.e. load babel early, though I doubt that this is the cause of your problem. – dpprdan Dec 18 '13 at 21:28

\documentclass[
a4paper,
bibliography=totoc,
listof=totoc,
final
]{scrreprt}


If you want to just add a pdf bookmark, you can use the command \pdfbookmark:

\pdfbookmark{\contentsname}{toc}
\tableofcontents

• Although I prefer this solution to the other given answers, because it makes use of KOMA-options, the bookmark might point the end of page right before the TOC. To solve this, change it to: \clearpage\phantomsection\pdfbookmark{\contentsname}{toc} \tableofcontents – dhst Mar 7 '12 at 20:02