3

I can manually set line numbers in an algorithm2e environment using the \nlset command (together with \LinesNotNumbered). However, I can't figure out how to make the same for lines with the end or else statements, as in the following picture:

Example algorithm2e output

1
  • If this question is still open, can you provide a compilable example ?
    – BambOo
    May 17, 2020 at 16:02

1 Answer 1

1

Here is a solution using

  • A special if-then-else construct called \nlIf
  • A wrapper macro \nlsetend redefining locally this \nlIf (to be called before it), to add the custom line number
\documentclass[margin=5mm]{standalone}
\usepackage{algorithm2e,amsmath} 

\newcommand{\nlsetend}[1]{%
\SetKwIF{nlIf}{ElseIf}{Else}{if}{then}{else if}{else}{\nlset{#1}end}
}
\begin{document}
\begin{algorithm}[H]
    \eIf{$\hdots$}{
        \eIf{$rank \neq \hdots$}{
            send\;
            send\;
        }{
            $\hdots$
        }
    }{
        $\hdots$\;
    }
    \eIf{$\hdots$}{
        \nlsetend{test}
        \enlIf{$rank \neq \hdots$}{
            send\;
            send\;
            }{
                $\hdots$
                }
                }{
                    $\hdots$\;
    }

\end{algorithm}
\end{document}

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .