# Different hierarchical levels in TOC and hyperref-generated PDF bookmarks

I would like to make hyperref generate bookmarks for all available hierarchical levels of my documents, but only in the produced PDF. For the TOC itself (i.e. the one printed at the beginning of the document), however, I would like to display only the first 2 or 3 levels, to make it more compact.

But from what I understand, the only way to change the depth in the PDF bookmarks is to change that of the TOC, using the command \setcounter{tocdepth}{x}.

Is there an alternate way of controlling this depth, which would allow using a different value for the TOC and for the PDF bookmarks?

Edit: Here's a minimal example. By default, the 3 hierarchical levels are displayed in both the TOC and PDF bookmarks. By uncommenting the 4th line, one can limit the depth to the 2nd level, but this is applied to both the TOC and PDF bookmarks. I would like it only to apply to the TOC, and keep the 3rd level in the PDF bookmarks.

\documentclass{article}
\usepackage{hyperref}

\begin{document}

%\setcounter{tocdepth}{2}
\tableofcontents

\section{This should be in both the TOC and bookmarks}
\subsection{This too}
\subsubsection{But this should appear only in the bookmarks}
\subsubsection{and this also}

\end{document}

• your initial approach with \setcounter{tocdepth{2} was fine, you only needed to also use \setcounter{tocdepth}{3} immediately after \tableofcontents. – user4686 Mar 19 '14 at 20:50
• I have converted my comment into an answer; but I realize now that the code of your OP is in contradiction with its first paragraph: there you say you want a more compact TOC (only two levels) but in the code sample you ask for the subsubsections to be only in the TOC. For this you would need to set the tocdepth to 3 before and 2 after, which is the opposite of what is in my answer, which achieves the "more compact TOC" case. – user4686 Mar 19 '14 at 20:58
• You're right, I made a mistake in the \subsubsection line (it should be only in the bookmarks). I've corrected my example. Thanks! – Vincent Labatut Mar 19 '14 at 22:19

You can control the bookmark depth just like you can the ToC depth using the bookmarksdepth key-value:

\usepackage{hyperref}% http://ctan.org/pkg/hyperref
\hypersetup{bookmarksdepth=3}


bookmark also adapts this so you can use

\usepackage{bookmark}% http://ctan.org/pkg/bookmark
\bookmarksetup{depth=3}

• Great, that's exactly what I wanted! I thought I had considered all hyperref parameters, but apparently I was wrong. Thanks! – Vincent Labatut Mar 3 '14 at 20:44
• It appears that this option isn't in the hyperref documentation, although it also works for me just fine. – Teepeemm May 30 '18 at 16:20

The tocdepth counter has (except if some package fiddles with the sectioning commands and changes the default behavior) no bearing on what gets written to the .toc file. However, it does have (by default) an influence, under the hyperref regime, on what makes its way to the pdf bookmarks.

Thus your original problem could also be solved by modifying tocdepth only temporarily at the time of \tableofcontents.

\setcounter{tocdepth}{2}
\tableofcontents
\setcounter{tocdepth}{3}


for example.