[Tex/LaTex] Disable line numbering of specific lines

algorithm2ealgorithmskeywordsline-numbering

Is there way how to turn off numbering of lines for specific line in algorithm2e? I need bold : after keyword. So I tried redefine these macros:

\renewcommand{\KwIn}[1]{\textbf{Input:} #1}
\renewcommand{\KwOut}[1]{\textbf{Output:} #1}

But after try of this:

\begin{algorithm}[h]  

\SetAlgoNoLine
\DontPrintSemicolon
\LinesNumbered

\KwIn{$(X_{t-1}, u_t, z_t)$}\\
\KwOut{$X_t$}
...
...
...
\end{algorithm}

algorithm

So I need turn off line numbering of 2 first lines (keyword lines). Or specify new keyword which will have bold : after keyword name. This \SetKwInput{Input}{Input} is generating only normal : after Input name (Input: (X…)). I was searching in documentation how adjust style of input/output keywords but nothing about ending : found. Can anybody help?

Best Answer

Here's one possibility redefining \SetKwInOut:

\documentclass{article}
\usepackage[linesnumbered]{algorithm2e}

\makeatletter
\renewcommand{\SetKwInOut}[2]{%
  \sbox\algocf@inoutbox{\KwSty{#2}\algocf@typo:}%
  \expandafter\ifx\csname InOutSizeDefined\endcsname\relax% if first time used
    \newcommand\InOutSizeDefined{}%
    \sbox\algocf@inoutbox{\KwSty{#2}\algocf@typo\textbf{:}~}\setlength{\inoutindent}{\wd\algocf@inoutbox}%
  \else% else keep the larger dimension
    \ifdim\wd\algocf@inoutbox>\inoutsize%
    \sbox\algocf@inoutbox{\KwSty{#2}\algocf@typo\textbf{:}~}\setlength{\inoutindent}{\wd\algocf@inoutbox}%
    \fi%
  \fi% the dimension of the box is now defined.
  \algocf@newcommand{#1}[1]{%
    \ifthenelse{\boolean{algocf@inoutnumbered}}{\relax}{\everypar={\relax}}%
%     {\let\\\algocf@newinout\hangindent=\wd\algocf@inoutbox\hangafter=1\parbox[t]{\inoutsize}{\KwSty{#2}\algocf@typo\hfill:}~##1\par}%
    {\let\\\algocf@newinout\hangindent=\inoutindent\hangafter=1\KwSty{#2}\algocf@typo\textbf{:}~##1\par}%
    \algocf@linesnumbered% reset the numbering of the lines
  }}%
\makeatother
\begin{document}

\begin{algorithm}
\SetKwInOut{Input}{Input}
\SetKwInOut{Output}{Output}
\Input{A bitmap $Im$ of size $w\times l$}
\Output{A partition of the bitmap}
\BlankLine
\emph{special treatment of the first line}\;
\For{$i\leftarrow 2$ \KwTo $l$}{
\emph{special treatment of the first element of line $i$}\;
}
\caption{disjoint decomposition}\label{algo_disjdecomp}
\end{algorithm}\DecMargin{1em}


\end{document}

enter image description here