[Tex/LaTex] way to reference the line number in algorithm 2e


Say I have algorithm appear as followed

enter image description here

Is it possible to reference the line number using ~\ref or any other possiblities?

Best Answer

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.




Line \ref{alg:goto} is important.


\KwData{this text}
\KwResult{how to write algorithm with \LaTeX2e }
\While{not at end of this document}{
read current\;
go to next section\;\label{alg:goto}
current section becomes this one\;
go back to the beginning of current section\;


The output:

Line 5

Related Question