# Can hyperref be made to include the TOC in a PDF contents navigator?

Simple minimal document

\documentclass[a4paper,10pt]{scrbook}

\usepackage{hyperref}

\begin{document}

\chapter*{Preface}
This is the preface.

\tableofcontents

\chapter{Chapter One}
This is chapter one.

\end{document}


By using hyperref, pdflatex produces a "Contents" section in the PDF file. This handy navigator does not include the TOC itself, for this document it only contains "Chapter One". I want my PDF Contents to include a link to the on-page TOC. (Naturally I don't want the on-page TOC to contain itself.) Is this possible?

• Have you tried: putting\pdfbookmark[1]{Name}{Anchor} just before calling \tableofcontents where [1] is the level at which the bookmark should appear. You may need a \clearpage or \cleardoublepage before setting the bookmark to ensure it points to the right position. – Wiebke Jan 16 '17 at 14:18

The package tocbibind will add the ToC to the ToC itself, since hyperref is loaded, there will be ToC entry in the bookmarks itself. If the ToC should not appear in the ToC, temporarily decrease the tocdepth counter to -2 which means that nothing will be written to the ToC, use the old \latextableofcontents command and write an increased value for the tocdepth counter to the ToC file.

\documentclass[a4paper,10pt]{scrbook}

\usepackage{tocbibind}
\usepackage{hyperref}

\usepackage{bookmark}

\AtBeginDocument{%
\let\latextableofcontents\tableofcontents

\renewcommand{\tableofcontents}{%
\latextableofcontents%
}
}

\begin{document}

\chapter*{Preface}
This is the preface.

\tableofcontents

\chapter{Chapter One}
This is chapter one.

\end{document}


• tocbibind is not recommended if you are using a KOMA-Script class. – Schweinebacke Jan 16 '17 at 14:45
• @Schweinebacke: Well, I know that. I don't recommend KOMA in turn ;-) – user31729 Jan 16 '17 at 14:46

You can use \BeforeTOCHead to add a \pdfbookmark just before the heading of the table of contents. You need an additional \cleardoublepage before the \pdfbookmark otherwise the bookmark will be added to the last page of chapter preface.

\documentclass[a4paper,10pt]{scrbook}

\usepackage{hyperref}

\begin{document}

\chapter*{Preface}
This is the preface.

\tableofcontents

\chapter{Chapter One}
This is chapter one.

\end{document}


If you want similar additions for the list of figures or the list of tables, you may use:

\BeforeTOCHead[lof]{\cleardoublepage\pdfbookmark{\listfigurename}{lof}}

Alternatively you can add option listof=totoc to \documentclass, which would add these lists also to the table of contents. But don't use both!
• The second mandatory argument of \pdfbookmark is used to generate a unique anchor for the bookmark. I would not use \contentsname, depending on the language, it might contain "funny" stuff. Therefore, a plain ASCII letter string like "toc" avoids this. Example: \pdfbookmark{\contentsname}{toc} – Heiko Oberdiek Jan 16 '17 at 20:02