Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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?

share|improve this question
add comment

1 Answer

up vote 2 down vote accepted

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

share|improve this answer
    
I'm getting error while compiling: ! Undefined control sequence. <argument> \inoutindent l.177 \SetKwInOut{Output}{Output}. And could you also give me possibility with KwIn and KwOut? Because I don't need same vertical align of :. Thanks for help anyway. –  Petr Přikryl Mar 27 '13 at 15:33
1  
@PetrPřikryl I updated my answer to suppress vertical alignment. Regarding the error message, please update your packages. My code will work with version 5.0 (january 06 2013) of algorithm2e. –  Gonzalo Medina Mar 27 '13 at 15:54
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.