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.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm using the hyperref package with a custom class, and I'm having a problem with hyperref not creating the tree correctly. What I expect to see is this:

+ Section 1
++ Section 1.1
++ Section 1.2
+++ Section 1.2.1
+++ Section 1.2.2
++ Section 1.3
+ Section 2
++ Section 2.1

But what I'm seeing instead is this:

+ Section 1
++ Section 1.1
++ Section 1.2
+++ Section 1.2.1
+++ Section 1.2.2
++++ Section 1.3
+++++ Section 2
++++++ Section 2.1

I am guessing there is some kind of level counter that keeps track of what level of section, subsection, subsubsection, etc. the tree is on, and this just isn't being reset when I run \clearpage or when I create a chapter or section header. But I don't know how to reset it, and I don't know what kind of mechanism hyperref uses to keep track of this. I've been unable to figure out how hyperref does this on my own.

How can I control hyperref's level "counter" from the Latex class level?

Any help would be greatly appreciated.

share|improve this question
Off the cuff, I would imagine hyperref uses the counter secnumdepth to identify the indentation/level of the section. I'm guessing your 'custom class' has a \addtocounter{secnumdepth}{1} somewhere in the \section{...} and \subsection{...} definition. Perhaps even a conditional increment since some of the section/subsections are at the same level. – Werner Aug 9 '11 at 21:38
@user463213: Try adding \usepackage{etoolbox} \pretocmd{\section}{\addtocounter{secnumdepth}{-1}}{}{} \pretocmd{\subsection}{\addtocounter{secnumdepth}{-1}}{}{} to your preamble to drop the secnumdepth counter by one and revert your documentclass changes. – Werner Aug 24 '11 at 5:26

The most likely culprit here is the "custom class" that redefines the way sections are typeset. Specifically, there could be an increase in secnumdepth rather that setting it explicitly. Your choices are:

  • either edit the custom document class and fix this \addtocounter problem by removing it, and replacing it with the correct, fixed, secnumdepth. For example, in the \section command, use \setcounter{secnumdepth}{3}. In \subsection, remove \addtocounter and use \setcounter{secnumdepth}{4}. In \subsubsection, remove \addtocounter and use \setcounter{secnumdepth}{5}. This will ensure that the respective sectioning command sit at different levels.
  • Use the etoolbox package to prepend a single drop in the required counter before expanding as usual. That is, by adding

    \usepackage{etoolbox}% http://ctan.org/pkg/etoolbox
share|improve this answer

Your Answer


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.