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:
-
If this question is still open, can you provide a compilable example ?– BambOoMay 17, 2020 at 16:02
1 Answer
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}