LaTeX伪代码如何将两部分分别显示行数
在LaTeX伪代码中,可以使用algorithm2e宏包中的\SetAlgoLined和\SetNoFillComment命令来分别为伪代码的两部分设置行号和注释。具体实现方式如下:
\documentclass{article} \usepackage{algorithm2e}
\begin{document}
\begin{algorithm}[H] \SetAlgoLined \KwData{input data} \KwResult{output result}
\tcp{Part 1} \For{each item in the data}{ process(item); }
\SetNoFillComment \tcp{Part 2} \While{condition}{ do something; } \end{algorithm}
\end{document}
在上述代码中,\SetAlgoLined命令将第一部分的伪代码设置为带有行号和注释的形式,\SetNoFillComment命令则将第二部分的伪代码设置为只带有行号的形式。实现效果如下图所示:
注意:\SetNoFillComment命令将不会为第二部分的伪代码添加注释。如果需要为第二部分添加注释,则需要使用\tcc命令手动添加注释
原文地址: https://www.cveoy.top/t/topic/eyUM 著作权归作者所有。请勿转载和采集!