8

I'm using the LaTeX algorithm2e package by defining

\usepackage[ruled, linesnumbered, vlined]{algorithm2e}

The linesnumbered argument adds lines numbers from [1,...,n] if we have an algorithm with n lines. I would like to know if there's any possibility to change the numbers in something like: [1*,...,n*] (adding a symbol like a * or a ' behind the number). Note I have several algorithms in my document, thus I want to define the above described "different line number style" in a local \begin{algorithm} ... \end{algorithm} scope. I am thankful for all help and information.

8

Use the command \SetNlSty to change the style of the numbering. It takes three argumnts, the first is the font to use, the second the text to appear before the number and the third the text to appear after. Thus

\SetNlSty{textbf}{}{*}

will place * after the line numbers, all bold face (which is the default font).

Sample output

\documentclass{article}

\usepackage[ruled,linesnumbered,vlined]{algorithm2e}

\begin{document}

\begin{algorithm}
  \eIf {\( x>y \)}{greater}{less than or equal}
\end{algorithm}

\SetNlSty{textbf}{}{*}

\begin{algorithm}
  \eIf {\( x>y \)}{greater}{less than or equal}
\end{algorithm}

\end{document}
  • thats exactly the representation i was looking for - thank you for the clear answer! – Daniel F Feb 27 '13 at 11:28
  • How can we easily change lline numbers like IF which begins on line 786 end has END on 912? – Jan Filip Jul 7 at 19:21
  • @JanFilip Could you clarify? It would probably be best to ask a new question showing what output you desire. – Andrew Swann Jul 12 at 9:28

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.