![如何从 algorithm2e 中的 \tcc 注释中删除行号](https://linux22.com/image/479465/%E5%A6%82%E4%BD%95%E4%BB%8E%20algorithm2e%20%E4%B8%AD%E7%9A%84%20%5Ctcc%20%E6%B3%A8%E9%87%8A%E4%B8%AD%E5%88%A0%E9%99%A4%E8%A1%8C%E5%8F%B7.png)
我正在尝试使用编写算法algorithm2e
。我必须\tcc
在算法的不同阶段使用注释。当我在代码中添加\tcc
注释时,在输出中,每个\tcc
注释都会显示行号。示例代码如下,输出也附在此处。
有人能建议我如何从\tcc
注释中删除行号吗?在图片中,我突出显示了那两\tcc
行,我不想在其中显示任何行号。相反,我希望行号从“初始化”开始,即在输出中显示步骤 2 而不是步骤 1。
\begin{algorithm}[H]
\caption{How to write algorithms}
\tcc{Start of Example 1}
\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\;
}
}
\tcc{End of Example 1}
\end{algorithm}
答案1
基于你之前的问题您正在使用以下algorithm2e
选项:
\usepackage[linesnumbered,lined,boxed,commentsnumbered]{algorithm2e}
commentsnumbered
如果您不想对注释行进行编号,请删除该选项...
\documentclass{article}
\usepackage[linesnumbered,lined,boxed]{algorithm2e}
\begin{document}
\begin{algorithm}[H]
\caption{How to write algorithms}
\tcc{Start of Example 1}
\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\;
}
}
\tcc{End of Example 1}
\end{algorithm}
\end{document}