[Tex/LaTex] Algorithm2e modify line numbers

algorithm2eformattingline-numbering

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.

Best Answer

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}