2

I trying to customize the line number of my algorithm with the algorithm2e package. I want to start the line number at a specific line or just a given line. I am using the following code example:

\documentclass{article}

\usepackage[linesnumbered,ruled,vlined]{algorithm2e}

\begin{document}

\begin{algorithm}[!ht]
\caption{Overlapped Co-Clustering}
\DontPrintSemicolon
\SetNoFillComment
\footnotesize

\SetKwInOut{Input}{Input}
\SetKwInOut{Output}{Output}
\SetKwFunction{OCoClus}{OCoClus}

\Input{Input dataset D, Max number of co-clusters K \textit{\{optional\}}, Max object noise threshold $\epsilon_I$ \textit{\{optional\}}, Max attribute noise threshold $\epsilon_J$ \textit{\{optional\}}}
\Output{Set of disjoint and overlapped co-clusters $\Phi$}

\OCoClus{D,K,$\epsilon_I$,$\epsilon_J$}\;
$\prod \leftarrow \emptyset$\;
$D_{r} \leftarrow D$ \textit{\{residual matrix\}}
\end{algorithm}

\end{document}

It generates the following output:

enter image description here

I want that the second line (line number 2) starts with 1 and the first line (line number 1) is not numbered. I did not found a way to do this.

2
  • You should take a look here
    – Enevevet
    Commented Aug 13, 2021 at 23:16
  • Hi @Enevevet. I saw this answer, but it does not work for me. Because of that, I asked it. Tkx Commented Aug 14, 2021 at 23:40

1 Answer 1

1

The following code introduces \nlnonumber that removes the functionality of \nl - the line numbering mechanism - just for that line. Place it at the start of the line.

enter image description here

\documentclass{article}

\usepackage[linesnumbered,ruled]{algorithm2e}

\SetKwInOut{Input}{Input}
\SetKwInOut{Output}{Output}
\SetKwFunction{OCoClus}{OCoClus}
\DontPrintSemicolon
\SetNoFillComment

\let\oldnl\nl
\newcommand{\nlnonumber}{\renewcommand{\nl}{\let\nl\oldnl}}

\begin{document}

\begin{algorithm}
  \caption{Overlapped Co-Clustering}

  \Input{%
    Input dataset $D$, 
    Max number of co-clusters $K$ \textit{\{optional\}}, 
    Max object noise threshold $\epsilon_I$ \textit{\{optional\}}, 
    Max attribute noise threshold $\epsilon_J$ \textit{\{optional\}}}
  \Output{Set of disjoint and overlapped co-clusters $\Phi$}

  \nlnonumber
  \OCoClus{$D$, $K$, $\epsilon_I$, $\epsilon_J$}\;
  $\prod \leftarrow \emptyset$\;
  $D_r \leftarrow D$ \textit{\{residual matrix\}}
\end{algorithm}

\end{document}
1
  • Tkx, Werner. Now it worked for me. I tried your previous answer that the Enevevet pointed out, but it does not work for me. I did not recognize why, however, this answer works for me. Tkx. Commented Aug 14, 2021 at 23:45

Not the answer you're looking for? Browse other questions tagged .