Say I have algorithm appear as followed
Is it possible to reference the line number using ~\ref or any other possiblities?
Say I have algorithm appear as followed
Is it possible to reference the line number using ~\ref or any other possiblities?
Yes, it's possible. :)
Use the normal \label
command in the line you want to refer (page 4 of the algorithm2e
manual), then use \ref
to display the line number.
\documentclass{article}
\usepackage[linesnumbered]{algorithm2e}
\begin{document}
Line \ref{alg:goto} is important.
\vspace{2em}
\begin{algorithm}[H]
\KwData{this text}
\KwResult{how to write algorithm with \LaTeX2e }
initialization\;
\While{not at end of this document}{
read current\;
\eIf{understand}{
go to next section\;\label{alg:goto}
current section becomes this one\;
}{
go back to the beginning of current section\;
}
}
\end{algorithm}
\end{document}
The output: