[Tex/LaTex] Algorithm in IEEE format

algorithmicalgorithmsieeetran

I want to type an algorithm in ieee format. I have used algorithmic package. But using that package, I couldn't type a caption to the algorithm and "Algorithm " above the written algorithm. What should I do to get those things written in my algorithm ? I need the algorithm as in the given figure.enter image description here

The structure I have used is given below

 \documentclass{IEEEtran}
 \usepackage{algorithmic}
 \begin{document}
 %\begin{algorithm}
 %\caption{Algorithm for ...}
 \begin{algorithmic}[1]
 \renewcommand{\algorithmicrequire}{\textbf{Input:}}
 \renewcommand{\algorithmicensure}{\textbf{Output:}}
 \REQUIRE in
 \ENSURE  out
 \\ \textit{Initialisation} :
  \STATE first statement
 \\ \textit{LOOP Process}
  \FOR {$i = l-2$ to $0$}
  \STATE statements..
  \IF {($i \ne 0$)}
  \STATE statement..
  \ENDIF
  \ENDFOR
 \RETURN $P$ 
 \end{algorithmic} 
 %\end{algorithm}
 \end{document}

Best Answer

First of all, if you want to use the algorithm environment and also want to respect the IEEE format (which doesn't allow it to float), you can use the H floating specifier to tell algorithm not to float:

\begin{algorithm}[H]

Then, it seems that you want to use the ruled style for the algorithm environment, but without lines.

This can be achieved defining a new floating style (the algorithm package loads the float package), let's say norules, which has no rules

\makeatletter
\newcommand\fs@norules{\def\@fs@cfont{\bfseries}\let\@fs@capt\floatc@ruled
  \def\@fs@pre{}%
  \def\@fs@post{}%
  \def\@fs@mid{\kern3pt}%
  \let\@fs@iftopcapt\iftrue}
\makeatother

and applying it to the algorithm environment

\floatstyle{norules}
\restylefloat{algorithm}

MWE:

\documentclass{IEEEtran}

\usepackage{algorithm}
\usepackage{algorithmic}

\makeatletter
\newcommand\fs@norules{\def\@fs@cfont{\bfseries}\let\@fs@capt\floatc@ruled
  \def\@fs@pre{}%
  \def\@fs@post{}%
  \def\@fs@mid{\kern3pt}%
  \let\@fs@iftopcapt\iftrue}
\makeatother
\floatstyle{norules}
\restylefloat{algorithm}

\begin{document}

 \begin{algorithm}[H]
 \caption{Algorithm for ...}
 \begin{algorithmic}[1]
 \renewcommand{\algorithmicrequire}{\textbf{Input:}}
 \renewcommand{\algorithmicensure}{\textbf{Output:}}
 \REQUIRE in
 \ENSURE  out
 \\ \textit{Initialisation} :
  \STATE first statement
 \\ \textit{LOOP Process}
  \FOR {$i = l-2$ to $0$}
  \STATE statements..
  \IF {($i \ne 0$)}
  \STATE statement..
  \ENDIF
  \ENDFOR
 \RETURN $P$
 \end{algorithmic}
 \end{algorithm}

\end{document} 

Output:

enter image description here

Related Question