Algorithm2e 中仅包含没有关键字的数字行

Algorithm2e 中仅包含没有关键字的数字行

对于 Algorithm2e 中的算法,我只想对以分号结尾的行进行编号\;

我尝试使用以下答案来破解一些东西Algorithm2e - 禁用特定行的行号

\let\oldnl\nl
\newcommand{\nonl}{\renewcommand{\nl}{\let\nl\oldnl}}
\let\oldKwSty\KwSty
\renewcommand{\KwSty}[1]{\nonl\textnormal{\textbf{#1}}\unskip}

我希望这可以禁用带有关键字的行编号,但它不能完全按要求工作:

\documentclass{article}
\usepackage[ruled, linesnumbered]{algorithm2e}
\let\oldnl\nl
\newcommand{\nonl}{\renewcommand{\nl}{\let\nl\oldnl}}
\let\oldKwSty\KwSty
\renewcommand{\KwSty}[1]{\nonl\textnormal{\textbf{#1}}\unskip}
\begin{document}
\begin{algorithm}[H]
%\SetLine
\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\;
current section becomes this one\;
}{
go back to the beginning of current section\;
}
}
\caption{How to write algorithms}
\end{algorithm}
\end{document}

给予 算法编号不足

我希望其他带有分号的行也被编号(即从 1 到 5)。

我也尝试修改\;命令,我所做的任何更改要么打印行末的数字,要么修改下一行的行为。

相关内容