Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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?

share|improve this question
5  
You have accepted 50% of your answered questions. All your questions are excellent answered. We don't put any thanks in our question but you should thank users by upvoting [his/her] answer (with the upward pointing arrow to the left of it). Some users are ignoring questions where the OP has such an accepting rate. I am one of them. –  Marco Daniel Aug 7 '12 at 19:03
add comment

1 Answer

up vote 11 down vote accepted

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:

Line 5

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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