Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I'm trying to figure out how to manage the interaction of numbering features of various document parts, e.g., parts, chapters, sections, etc. and the bookmarks generated for a PDF document.

First, the number of document partition is only showing up for parts in the bookmarks. The numbers of chapters and section are not part of the names that are displayed. Is there a way to fix this?

Also, I've noticed that if a partition is not numbered (e.g., an unnumbered subsection) it doesn't show up as a bookmark. I would like to be able to have unnumbered subsections, for example, but still have them show up as bookmarks. Is there a way to do this?

To be clear on what I want to achieve, consider the following example:


\documentclass{book}
\begin{document}
\part{A} %Shows up as a bookmark named "I A"; this is fine
    \chapter{B} %Shows up as a bookmark named "B"; what I want is "1 B"
      \section{C} %Shows up as a bookmark named "C"; what I want is "1.1 C"
        \subsection*{D} %Doesn't show up as bookmark; what I want is "D"
  \part{E} %Shows up as a bookmark named "II B"; this is fine
    \chapter{F} %Shows up as bookmark named "F"; what I want is "2 F"
    %...and so on
\end{document}

share|improve this question
1  
The bookmark package allows you to have "free reign" over what is bookmarked/not and at different levels - and its functionality forms part of the hyperref package, if you're already using it. Would you be able to provide an MWE with some detail on what should be included/not and how. On a related note, the secnumdepth counter has an impact on what is displayed in the ToC (and also the PDF bookmarks). –  Werner Nov 19 '11 at 21:21
    
@Werner I've been looking at the bookmark package but maybe I'm overlooking a relevant part of the documentation. I will try to make my question more detailed so that it's clear what is happening and what I'm trying to accomplish. –  3Sphere Nov 19 '11 at 21:58
    
I've added an answer that is very generic and references some of the usages of the bookmark package. Let me know if this solves your problem. If not, as you mentioned, give more detail. –  Werner Nov 19 '11 at 21:59

1 Answer 1

up vote 11 down vote accepted

Assuming that you're using hyperref already*, the documentation states:

Usually hyperref automatically adds bookmarks for \section and similar macros. But they can also set manually.

The manual setting is performed using

\pdfbookmark[<level>]{<text>}{<name>}

where \part is level -1, \chapter is level 0, \section is level 1, ... It places <text> in the bookmarks and can be referenced internally (via a hyperlink) as <name>. Or, if you want to place it at a level relative to the current one, use

\currentpdfbookmark{<text>}{<name>}
\subpdfbookmark{<text>}{<name>}
\belowpdfbookmark{<text>}{<name>}

where <text> and <name> have similar meanings as before.

In the following MWE, hyperref creates sectional bookmarks for every unstarred heading up to secnumdepth and only the numbered, unstarred versions show up in the ToC. The starred versions, removed from the ToC by default, are included using some variation of \...pdfbookmark:

enter image description here

\documentclass{book}
\usepackage{hyperref}% http://ctan.org/pkg/hyperref
\usepackage{bookmark}% http://ctan.org/pkg/bookmark
\usepackage{lipsum}% http://ctan.org/pkg/lipsum
\begin{document}
\tableofcontents
\part{FIRST PART}
\chapter{First chapter} \lipsum[1]
\section{First section} \lipsum[2]
\section*{Second section} \currentpdfbookmark{Second section}{ch:1:sec:2} \lipsum[3]
\section{Third section} \lipsum[4]
\subsection{First subsection} \lipsum[5]
\subpdfbookmark{First subsubsection}{ch:1:sec:3:ssec:1:sssec:1}\subsubsection{First subsubsection} \lipsum[6]
\currentpdfbookmark{Second subsubsection}{ch:1:sec:3:ssec:1:sssec:2} \subsubsection*{Second subsubsection} \lipsum[7]
\subsection{Second subsection} \lipsum[8]
\currentpdfbookmark{Third subsection}{ch:1:sec:3:ssec:3} \subsection*{Third subsection} \lipsum[9]
\pdfbookmark[2]{Fourth subsection}{ch:1:sec:3:ssec:4}\subsection*{Fourth subsection} \lipsum[10]
\subsection{Fifth subsection} \lipsum[11]
\chapter{Second chapter} \lipsum[12]
\end{document}

For the inclusion of sectional numbers in the PDF bookmark panel, use the bookmarksnumbered option of hyperref:

\usepackage[bookmarksnumbered]{hyperref}% http://ctan.org/pkg/hyperref

The above MWE will then produce:

enter image description here

* If not, the bookmark package provides similar, stand-alone functionality for inclusion of PDF bookmarks in your document. In fact, hyperref suggests using it as improved bookmark organization.

share|improve this answer
    
Actually, this answers one of my questions; the \currentpdfbookmark command is the key to solving the problem of unnumbered sections not being displayed as bookmarks. Still trying to figure out though how to get the generated bookmark names for the (numbered) sections to include the appropriate number as part of the text –  3Sphere Nov 19 '11 at 22:18
    
@3Sphere: I just updated the answer to show how to include the sectional numbering - use the bookmarksnumbered option of hyperref. –  Werner Nov 19 '11 at 22:20
    
Thanks! I now understand how to deal with this issues. –  3Sphere Nov 19 '11 at 22:43
    
If you dislike having the section name in the code twice, you can use e.g. \subsection*{A}\pdfbookmark[2]{\GetTitleStringResult}{label}. –  Raphael Jun 11 at 9:02

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.