关闭 tcolorbox 和 adjustbox 时避免在算法中进行行编号

关闭 tcolorbox 和 adjustbox 时避免在算法中进行行编号

当关闭算法中的 tcolorbox 和 adjustbox 时,其命令对应的代码行会按编号显示。如何才能防止以下代码中显示标题旁边的 1(见下图)?

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[linesnumbered]{algorithm2e}
\usepackage{ float, tcolorbox, adjustbox}
\begin{document}

\begin{algorithm}[htp!]
\begin{adjustbox}{width=0.9\textwidth} \begin{tcolorbox}[left=20pt] 
\setcounter{AlgoLine}{0}
\KwData{X: some description o fthe data}
\KwData{Y: other data to describe}
\vspace*{5pt}
\hrule
\vspace*{5pt}
here is the first lone of the code \;
\For{ condition }{
    wow for loop!! \;
    \For {condition}{
        \While{condition}{
        that's intriguing;
        \While{indx in indxs or empty}{indx  $\leftarrow$ rblabla\;}}
    blabla\;
    \For{condition}{
      blabla\;
      blabla\;}}}
      %here I should put something to stop the numbering
      \end{tcolorbox}  \end{adjustbox} 
\caption{my caption}\label{alg:this}
\end{algorithm}
\end{document}

代码输出

答案1

以下内容可能足以删除孤立的行号:

在此处输入图片描述

\documentclass{article}

\usepackage[linesnumbered]{algorithm2e}
\usepackage{tcolorbox, adjustbox}

\begin{document}

\begin{algorithm}
  \SetNlSty{@gobble}{}{}% Remove line numbering
  \begin{adjustbox}{width=0.9\textwidth}
    \SetNlSty{textbf}{}{}% Default line numbering style
    \setcounter{AlgoLine}{0}% Restore default line numbering start
    \begin{tcolorbox}[left=20pt]
      \KwData{X: some description o fthe data}
      \KwData{Y: other data to describe}
      \vspace*{5pt}
      \hrule
      \vspace*{5pt}
      here is the first lone of the code \;
      \For{ condition }{
        wow for loop!! \;
        \For {condition}{
            \While{condition}{
            that's intriguing;
            \While{indx in indxs or empty}{indx  $\leftarrow$ rblabla\;}}
        blabla\;
        \For{condition}{
          blabla\;
          blabla\;}}}
          %here I should put something to stop the numbering
    \end{tcolorbox}
  \end{adjustbox} 
  \caption{my caption}
\end{algorithm}

\end{document}

我们将外面的行号设置\NlSty为,里面的行号恢复为 。虽然粗糙,但很实用。\@gobbletcolorbox

相关内容