# label in algorithmic

if I have this code

\begin{algorithm}
\label{alg:the_alg}
\begin{algorithmic}[1]
\STATE operation 0
\STATE operation 1
\end{algorithmic}
\end{algorithm}


I can make a reference to alg:the_alg. But, how I can make a reference to a STATE in algorithmic ?

-

You would use the same technique as you would with a regular label. The reference will be to the line number inside algorithmic:

\documentclass{article}
\usepackage{algorithm}% http://ctan.org/pkg/algorithms
\usepackage{algorithmic}% http://ctan.org/pkg/algorithmic
\begin{document}
\begin{algorithm}
\caption{This is an algorithm}
\label{alg:the_alg}
\begin{algorithmic}[1]
\STATE operation 0 \label{op0}
\STATE operation 1 \label{op1}
\end{algorithmic}
\end{algorithm}

See Algorithm~\ref{alg:the_alg}. More specifically, Operation~\ref{op1}.
\end{document}


Consider using the compatible (modernized) algorithmicx bundle which offers algpseudocode. Here's a duplicate of the above MWE, now with the updated algpseudocode package from algorithmicx:

\documentclass{article}
\usepackage{algorithm}% http://ctan.org/pkg/algorithms
\usepackage{algpseudocode}% http://ctan.org/pkg/algorithmicx
\begin{document}
\begin{algorithm}
\caption{This is an algorithm}
\label{alg:the_alg}
\begin{algorithmic}[1]
\State operation 0 \label{op0}
\State operation 1 \label{op1}
\end{algorithmic}
\end{algorithm}

See Algorithm~\ref{alg:the_alg}. More specifically, Operation~\ref{op1}.
\end{document}

-
in references, why some people use ~, example: ~\ref and not a whitespace \ref ? –  JuanPablo Jul 7 '12 at 22:40
@JuanPablo: To avoid a line break between the two since they're considered a "single unit". See Why should I put a ~ before \ref or \cite? –  Werner Jul 7 '12 at 23:08