You can use
\SetKwInOut{Parameter}{parameter}
and then
\Parameter{<text>}
in you algorithms. A complete example:
\documentclass{article}
\usepackage{algorithm2e}
\SetKwInOut{Parameter}{parameter}
\begin{document}
\begin{algorithm}
\SetKwData{Left}{left}
\SetKwData{This}{this}
\SetKwData{Up}{up}
\SetKwFunction{Union}{Union}
\SetKwFunction{FindCompress}{FindCompress}
\SetKwInOut{Input}{input}
\SetKwInOut{Output}{output}
\Input{A bitmap $Im$ of size $w\times l$}
\Output{A partition of the bitmap}
\Parameter{A parameter for the algorithm}
\BlankLine
\emph{special treatment of the first line}\;
\For{$i\leftarrow 2$ \KwTo $l$}{
\emph{special treatment of the first element of line $i$}\;
\For{$j\leftarrow 2$ \KwTo $w$}{\label{forins}
\Left$\leftarrow$ \FindCompress{$Im[i,j-1]$}\;
\Up$\leftarrow$ \FindCompress{$Im[i-1,]$}\;
\This$\leftarrow$ \FindCompress{$Im[i,j]$}\;
\If(\tcp*[h]{O(\Left,\This)==1}){\Left compatible with \This}{\label{lt}
\lIf{\Left $<$ \This}{\Union{\Left,\This}}\;
\lElse{\Union{\This,\Left}\;}
}
\If(\tcp*[f]{O(\Up,\This)==1}){\Up compatible with \This}{\label{ut}
\lIf{\Up $<$ \This}{\Union{\Up,\This}}\;
\tcp{\This is put under \Up to keep tree as flat as possible}\label{cmt}
\lElse{\Union{\This,\Up}}\tcp*[r]{\This linked to \Up}\label{lelse}
}
}
\lForEach{element $e$ of the line $i$}{\FindCompress{p}}
}
\caption{disjoint decomposition}\label{algo_disjdecomp}
\end{algorithm}
\end{document}
After the edit to the question, there's some incompatibility between elsarticle
and the new definition; in this case, you can move the new definition inside the algorithm
environment which can be done on a on-per-one basis or, as Werner suggested in his comment
, can be automated using
\makeatletter
\g@addto@macro{\@algocf@init}{\SetKwInOut{Parameter}{Parameters}}
\makeatother
A complete example:
\documentclass[preprint,3p,12pt,times]{elsarticle}
\usepackage[linesnumbered,algoruled,boxed,lined]{algorithm2e}
\makeatletter
\g@addto@macro{\@algocf@init}{\SetKwInOut{Parameter}{Parameters}}
\makeatother
\begin{document}
\begin{algorithm}[H]
\KwIn{Some input}
\Parameter{Some parameter}
\KwOut{Some output}
\caption{Some algorithm}\label{alg.mainLoop}
\end{algorithm}
\end{document}
Sounds like you are after \SetKwInput
, with syntax
\SetKwInput{<name>}{<keymord>}
which defines the macro \<name>{<arg>}
to print <keyword>
in keyword typography followed by :
, and then argument <arg>
.
A complete example:
\documentclass{article}
\usepackage[]{algorithm2e}
\SetKwInput{kwInit}{Init}
\begin{document}
\begin{algorithm}
\kwInit{$\alpha_n=1$ for all $n$}
\While{not at end of this document}{
do this and that
}
\end{algorithm}
\end{document}
The result:
Best Answer
algorithm2e
defines a command\SetKwBlock
which can be used to define new block structures. While the documentation says this command defines two variants, one for blocks with an explicit end-marker and one without, the latter actually doesn't seems to be defined. It could be used to build our let-in-structure from two such blocks.We thus have to resort to more low-level functions. The following code defines a new block structure
\LetIn{<definitions>}{<usage>}
based on patterns used by the\SetKwBlock
and\SetKwSwitch
macros:outputs