11

I am trying to set a bookmark of my abstract and my table of contents. The bookmark for the abstracts works fine but the bookmark for the toc links to the abstract instead to the toc. If I remove

\pdfbookmark[section]{Abstract}{toc}

the contents bookmark links fine to the toc...

I do not see where the mistake is and am thankful for any help!

Her is my MWE:

\documentclass{article}
\usepackage{hyperref, bookmark}

\begin{document}
%%%%%%%%%%%%%%%%%%% Abstract %%%%%%%%%%%%%%%%%%
\cleardoublepage
\phantomsection
\pdfbookmark[section]{Abstract}{toc}
\begin{abstract}
\end{abstract}

%%%%%%%%%%%%%%%%%%% Contents %%%%%%%%%%%%%%%%%%
\cleardoublepage
\phantomsection
\pdfbookmark[section]{\contentsname}{toc}
\tableofcontents

%%%%%%%%%%%%%%%%%%% Chapters %%%%%%%%%%%%%%%%%%
\cleardoublepage
\section{Introduction}
\cleardoublepage
\section{Sec 2}
\cleardoublepage
\section{Sec 3}

\end{document}
1
  • 1
    Welcome to TeX.SX! You can have a look at our starter guide to familiarize yourself further with our format. Commented Jul 29, 2016 at 22:26

1 Answer 1

12

The last argument of \pdfbookmark becomes the main part of the intern anchor name for the bookmark. The two invocations of \pdfbookmark use both toc with the same level. Therefore the document has two destinations with the same name, but a destination name must be unique. Thus instead of toc, the first \pdfbookmark could use abstract. Also \phantomsection is not needed, because \pdfbookmark already creates an anchor.

Example:

\documentclass{article}
\usepackage{hyperref, bookmark}

\begin{document}
%%%%%%%%%%%%%%%%%%% Abstract %%%%%%%%%%%%%%%%%%
\cleardoublepage
\pdfbookmark[section]{Abstract}{abstract}
\begin{abstract}
\end{abstract}

%%%%%%%%%%%%%%%%%%% Contents %%%%%%%%%%%%%%%%%%
\cleardoublepage
\pdfbookmark[section]{\contentsname}{toc}
\tableofcontents

%%%%%%%%%%%%%%%%%%% Chapters %%%%%%%%%%%%%%%%%%
\cleardoublepage
\section{Introduction}
\cleardoublepage
\section{Sec 2}
\cleardoublepage
\section{Sec 3}

\end{document}
1
  • Ah thank you! Easy one but sometimes you just don't see it. Thanks for the hint that I do not need the \phantompage before \pdfbookmark! :)
    – Sinaa
    Commented Jul 30, 2016 at 9:11

You must log in to answer this question.

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