# How to see the Steps number in an algorithm

In below algorithm I have used the package

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


1) How do I see steps number after step 2?

2) Is there any command apart from

\renewcommand{\labelenumi}{(\Roman{enumi})}


to get the item number as in roman font?

\begin{algorithm}
\DontPrintSemicolon % Some LaTeX compilers require you to use \dontprintsemicolon    instead
\KwIn{a,b,c,d}
\KwOut{e,r}
Calculate $x$, and $y$\\
Check,
\renewcommand{\labelenumi}{(\Roman{enumi})}
\begin{enumerate}[noitemsep,nolistsep]
\item If  $k \geq n$, then the  $m_{2}$.
\item If  $h \geq j$, then  $m_{1}$.
\end{enumerate}
Otherwise,\\
Initialisation: \textit{$g(0)=nj$}\\
$i=0$\\
Compute $n_{2}$,
$n(i)=\frac {a}{b(i)\sqrt{3v}}$\\
Update $b$,
$b(i+1)=( -\frac{1}{2(g(i)/D}+1)$\\
$i=i+1$,\\
Repeat \textit{Steps 3 to 6}, till $|a(i+1)-a(i) |<\epsilon$
\caption{algo of g}
\label{algo:b}
\end{algorithm}


Some changes and the numbers appear:

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

\begin{document}

\begin{algorithm}
%\DontPrintSemicolon % Some LaTeX compilers require you to use \dontprintsemicolon    instead
\KwIn{a,b,c,d}
\KwOut{e,r}
Calculate $x$, and $y$\\
Check, \linebreak
%\renewcommand{\labelenumi}{(\Roman{enumi})}
%\begin{enumerate}[noitemsep,nolistsep]
%\item
(I) If  $k \geq n$, then the  $m_{2}$.
\linebreak
%\item
(II) If  $h \geq j$, then  $m_{1}$.\\
%\end{enumerate}
Otherwise,\\
Initialisation: \textit{$g(0)=nj$}\\
$i=0$\\
Compute $n_{2}$,
$n(i)=\frac {a}{b(i)\sqrt{3v}}$\\
Update $b$,
$b(i+1)=( -\frac{1}{2(g(i)/D}+1)$\\
$i=i+1$,\\
Repeat \textit{Steps 3 to 6}, till $|a(i+1)-a(i) |<\epsilon$
\caption{algo of g}
\label{algo:b}
\end{algorithm}

\end{document}


I am not sure, which lines should be numbered, but the general idea is clear now, I hope.

• I have two if procedures in Step2, but in your code you have missed one if condtion. Commented Nov 5, 2013 at 0:12
• @Harry Corrected. Commented Nov 5, 2013 at 0:24

Here's an approach that uses the functionality provided by algorithm2e to form conditional and repetition structures. Of course, since you're calling the package with vlined, the output also includes this.

\documentclass{article}
\usepackage[linesnumbered,ruled,vlined]{algorithm2e}% http://ctan.org/pkg/algorithm2e
\DontPrintSemicolon
\begin{document}

\begin{algorithm}
\KwIn{$a$, $b$, $c$, $d$}
\KwOut{$e$, $r$}
Calculate~$x$ and~$y$\;
\lIf{$k \geq n$}{$m_2$}\;
\lIf{$h \geq j$}{$m_1$}\;
\Else{%
\Repeat{$|a(i+1)-a(i)| < \epsilon$}{%
Initialisation: $g(0) = nj$\;\label{stepA}
$i=0$\;
Compute~$n_2$
$n(i) = \frac{a}{b(i)\sqrt{3v}}$
\nl Update~$b$
$b(i+1) = (-\frac{1}{2(g(i)/D} + 1)$
\nl $i = i + 1$\;
}
}
\caption{My algorithm}
\label{algo:b}
\end{algorithm}

\end{document}


Note that, instead of manually referencing steps, you can use a regular \label and \ref it later.

I just ran into this problem myself. My solution was to put "{" and "}" before and after enumitem, i.e.

{
\begin{enumerate}[noitemsep,nolistsep]
\item If  $k \geq n$, then the  $m_{2}$.
\item If  $h \geq j$, then  $m_{1}$.
\end{enumerate}
}


I hope this solution works for you too (if you still need it).