algorithm2e の \tcc コメントから行番号を削除する方法

algorithm2e の \tcc コメントから行番号を削除する方法

を使用してアルゴリズムを記述しようとしています。アルゴリズムのさまざまな段階でコメントalgorithm2eを使用する必要があります\tcc。コードにコメントを追加すると\tcc、出力で各\tccコメントが行番号付きで表示されます。サンプル コードは以下のとおりです。出力も添付します。

コメントから行番号を削除する方法を教えていただけませんか\tcc。画像では、\tcc行番号を付けたくない 2 行を強調表示しています。代わりに、出力にステップ 1 ではなくステップ 2 として表示される「初期化」から始まる行番号を付けたいです。

出力

\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}

関連情報