如何從演算法2e中的\tcc註解中刪除行號

如何從演算法2e中的\tcc註解中刪除行號

我正在嘗試使用 編寫一個演算法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}

相關內容