30

I would like to add a bookmark to the table of contents. This page shows a method, but \pdfbookmark is not recognised as a command. This is my document header:

\documentclass[a4paper]{report}
\usepackage[pdftex,bookmarks=true]{hyperref}
\usepackage[pdftex]{graphicx}
\usepackage[utf8]{inputenc}
\usepackage{array}

I'm compiling the document with TexMakerX's PDFLaTeX option.

1

2 Answers 2

37

This works for me.

\documentclass[a4paper]{report}
\usepackage[utf8]{inputenc}
\usepackage{graphicx}
\usepackage{array}

\usepackage[bookmarks=true]{hyperref}
\usepackage{bookmark}

\begin{document}

\cleardoublepage
\pdfbookmark{\contentsname}{Contents}
\tableofcontents

\chapter{P}
Some text
\end{document}

Notice that the pdftex options should not be used, as it is supplied automatically when the LaTeX engine used is pdftex. Moreover hyperref should generally be loaded last, with some exception; one of the exceptions is bookmark that eases bookmark management (and is not strictly necessary).

The \cleardoublepage is redundant in the example, but is necessary if some copy precedes the table of contents to ensure the correct correspondence of the bookmark with the text.

10

The bookmark package seems to be a powerful and customizable solution, but for most (of my) applications, one usually needs to add the bookmark at or below the current level. For this it is sufficient to use what hyperref provides, namely \belowpdfbookmark{text}{name} and \subpdfbookmark{text}{name}.

As described here: http://mirrors.ctan.org/macros/latex/contrib/hyperref/doc/hyperref-doc.html#x1-150004.1

4
  • 5
    Loading the package bookmark has also the advantage, that the bookmarks are faster uptodate, often one run is sufficient, hyperref needs two runs. Oct 31, 2012 at 9:21
  • @HeikoOberdiek, good to know. Do you mean that you need a smaller number of compilation? I think I noticed that. Is this true even if you use the plain hyperref commands?
    – alfC
    Oct 31, 2012 at 14:27
  • Yes (and more text to make a comment). Oct 31, 2012 at 14:29
  • I found it useful to use both \belowpdfbookmark{text}{contents} and \pdfbookmark{other text}{contents} -- without this, having two \pdfbookmarks in my text was causing both of them to be listed on "page 1". Aug 18, 2013 at 18:41

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .