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.

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?

\documentclass{scrbook}
\usepackage[svgnames]{xcolor}
\usepackage{classicthesis}
\usepackage[english]{babel}
\usepackage[latin1]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[ruled, vlined, linesnumbered]{algorithm2e}  % references NOT OK
%\usepackage[ruled, vlined]{algorithm2e}  % references OK

\begin{document}

\chapter{Chapter}

Wrong reference -> \ref{label}

\subsection{Section}

\begin{algorithm}[htbp]
  \LinesNumbered
  i = 1
\end{algorithm}

\subsubsection{Sub Sub Section}
\label{label}

\end{document}
share|improve this question

1 Answer 1

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

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

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

 
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.