24

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.

30

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.

6

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://ftp.math.purdue.edu/mirrors/ctan.org/macros/latex/contrib/hyperref/doc/manual.html#x1-150004.1

  • 5
    Loading the package bookmark has also the advantage, that the bookmarks are faster uptodate, often one run is sufficient, hyperref needs two runs. – Heiko Oberdiek Oct 31 '12 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 '12 at 14:27
  • Yes (and more text to make a comment). – Heiko Oberdiek Oct 31 '12 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". – Joe Corneli Aug 18 '13 at 18:41

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.