TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

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

If I use the algorithm2e package together with the linesnumbered option and the classicthesis package, references to a sub sub section are wrong. If I don't use the linesnumbered option, references are correct. Is this a bug? Is there a work-around?

\usepackage[ruled, vlined, linesnumbered]{algorithm2e}  % references NOT OK
%\usepackage[ruled, vlined]{algorithm2e}  % references OK



Wrong reference -> \ref{label}


  i = 1

\subsubsection{Sub Sub Section}

share|improve this question
up vote 2 down vote accepted

\label picks up the most recent \@currentlabel that is set. And, in your case, this is the line inside the algorithm when you have linesnumbered activated. If your intent is to have a hyperlink point to the start of the subsection, you either need to insert a \phantomsection and update \@currentlabel to the appropriate counter manually

\def\@currentlabel{\thesubsection}% Update reference text
\phantomsection% Mark hyperref link location
\subsubsection{Sub Sub Section}

or you need to update the counter secnumdepth to actually also have your sub-sub-sections also numbered:

\setcounter{secnumdepth}{3}% Number up to \subsubsection

In the former case, the reference will show 1.0.1 (the value contained within \thesubsection) but point to the sub-sub-section. In the latter case, the reference will be correctly pointing to the sub-sub-section and have the appropriate number.

enter image description here

share|improve this answer
Thanks a lot! It's perfect! – user4811 Sep 24 '13 at 5:57

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.