1

I'm using the \includepdf command from the pdfpages package like this:

\chapter{Code}
\addcontentsline{toc}{section}{Introduction}
\includepdf[pages=-,addtotoc={1,subsection,2, Conditions, mylabelA}]{fname1}
\includepdf[pages=-,addtotoc={1,subsection,2, Blocks, mylabelB}]{fname2}

The chapter toc is fine but the bookmarks for the included pdfs are at the section level, aligned with the section title (Introduction):

\BOOKMARK [0][-]{toc.0}{Contents}{}% 1
\BOOKMARK [0][-]{chapter.1}{Code}{}% 2
\BOOKMARK [1][-]{section*.1}{Introduction}{chapter.1}% 3
\BOOKMARK [2][-]{section*.2}{Conditions}{chapter.1}% 4
\BOOKMARK [2][-]{section*.3}{Blocks}{chapter.1}% 5

How do I specify that the bookmarks should be at the subsection level so they nest underneath the section?

2

You are missing an anchor:

      Package hyperref Warning: The anchor of a bookmark and its parent's must not
(hyperref)                be the same. Added a new anchor on input line 26.

Add it with \phantomsection:

\documentclass{book}
\usepackage{pdfpages}
\usepackage{hyperref}
\begin{document}
\tableofcontents
\chapter{Code}
\phantomsection\addcontentsline{toc}{section}{Introduction}
\includepdf[pages=-,addtotoc={1,subsection,2, Conditions, mylabelA}]{example-image}
\includepdf[pages=-,addtotoc={1,subsection,2, Blocks, mylabelB}]{example-image}

\end{document}
  • Why is the phantomsection needed? Shouldn't the refstep in chapter be enough to provide an anchor? (just wondering) – daleif Aug 10 '17 at 20:45
  • @daleif: the chapter has its anchor, the problem is the following \addcontentsline, – Ulrike Fischer Aug 10 '17 at 20:47
  • But shouldn't that anchor be "global" so others can access it, or am I on the wrong path here? – daleif Aug 10 '17 at 20:50
  • 1
    @daleif: The bookmarks try to build an hierarchical structure, the section bookmark is a level below the chapter. This doesn't work with one anchor. hyperref realize this. – Ulrike Fischer Aug 10 '17 at 20:52

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.