# Problem with references in classic thesis if algorithm2e package is used

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}

-

\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

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.