[Tex/LaTex] Referencing line numbers in an algorithm

algorithmscross-referencing

Referencing figures is simple:

\begin{figure}
    \caption{Blah blah blah blah blah}
    \label{fig:name}
    %shtuff goes here
\end{figure}

See figure~\ref{fig:name}.

I would like to know if it is possible to reference line numbers in an algorithm, e.g.:

\begin{algorithmic}[1]
    \State blah1
    \State blah2 \label{lst:line:blah2}
    \State blah3
\end{algorithmic}

As you can see on line~\ref{lst:line:blah2} \ldots

Best Answer

Of course you can; here's a simple example based on your code snippet:

\documentclass{article}
\usepackage{algpseudocode}

\begin{document}

\begin{algorithmic}[1]
    \State blah1
    \State blah2 \label{lst:line:blah2}
    \State blah3
\end{algorithmic}

As you can see on line~\ref{lst:line:blah2} \ldots

\end{document}

enter image description here

Related Question