34

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
52

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

1
  • 2
    Oh wow. I didn't even try it out, I just assumed it would be more difficult. Thanks for the confirmation.
    – knpwrs
    Mar 11 '12 at 22:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.