I am using the cleveref
and hyperref
packages. This works well overall, but cross-references to lines in algorithms are incorrect.
I found some other related posts, this one and this one. However, solutions given there do not work for me.
Here is the MWE:
\documentclass[11pt]{report}
%% algorithms
\usepackage[chapter]{algorithm}
\usepackage{algpseudocode}
%% referencing
\usepackage{hyperref}
\usepackage{cleveref}
\begin{document}
\chapter{First chapter}
\begin{algorithm}[!htb]
\caption{First algorithm}
\begin{algorithmic}[1]
\State A statement in 1st algorithm
\end{algorithmic}
\end{algorithm}
\chapter{Second chapter}
A reference to a line in \cref{alg:secondalg} \ : \cref{step:insecondalg}
\begin{algorithm}[!htb]
\caption{Second algorithm} \label{alg:secondalg}
\begin{algorithmic}[1]
\State A statement in 2nd algorithm \label{step:insecondalg}
\end{algorithmic}
\end{algorithm}
\end{document}
The \cref
to the step in second chapter gives the right step number, but its link points to the algorithm in first chapter.
Please provide any solutions / workarounds that you may have.