# putting algorithm in box

\documentclass[journal,12pt]{IEEEtran}
\usepackage{algorithmic}
\usepackage{graphicx}
\usepackage{algorithm}
\usepackage{nicefrac}
\usepackage{mathtools}
\usepackage{tabularx,booktabs,ragged2e}

\begin{document}
%\begin{pseudocode}[<ovalbox>]{}{}
\textit{Algorithm 1}:  Collaborative Spectrum Sensing
%\begin{description}
\begin{enumerate}
\item[\textit{1.}] For each contributor $S_i$.
\item[\textit{2.}] Calculate the entropy.\newline
\item[\textit{3.}] Select the channel and proceeds as follows:
\begin{enumerate}
\item[ii.] Otherwise
\begin{enumerate}
\item[a.] Get the largest entropy
\item[b.]\begin{algorithmic}
\IF {($TTL$ $>$ 0)}
\STATE  Set $PRE$ field with its $ID$; \newline
\ELSE
\STATE discard $M$
\ENDIF
\end{algorithmic}
\end{enumerate}
\end{enumerate}
\item[\textit{4.}] Each user updates the prob of each action.
\end{enumerate}
%\end{pseudocode}
\end{document}

• If you indent your code by 4 spaces, it gets highlighted and is better readable. Concerning your request, I would put the algorithmic environment first and would try to use ony \STATEs (though I would have to look up how to use something like substates) – Ronny Dec 21 '15 at 5:51
• Typically one would leave the numbering (and indentation of the code) over to algorithmic, rather than setting it manually. This implies an arabic numbering throughout, rather than your nested arabic - roman - alphabetic enumeration. Would that work? – Werner Dec 21 '15 at 6:34

One way to draw the box would be to use mdframed:

## Code:

\documentclass[journal,12pt]{IEEEtran}
\usepackage{algorithmic}
\usepackage{graphicx}
\usepackage{algorithm}
\usepackage{nicefrac}
\usepackage{mathtools}
\usepackage{tabularx,booktabs,ragged2e}
\usepackage{xcolor}
\usepackage{showframe}
\usepackage[framemethod=tikz]{mdframed}

\begin{document}
\begin{mdframed}[
linecolor=red,
linewidth=2pt,
roundcorner=4pt,
backgroundcolor=olive!15,
userdefinedwidth=\textwidth,
]
%\begin{pseudocode}[<ovalbox>]{}{}
\textit{Algorithm 1}:  Collaborative Spectrum Sensing
%\begin{description}
\begin{enumerate}
\item[\textit{1.}] For each contributor $S_i$.
\item[\textit{2.}] Calculate the entropy.\newline
\item[\textit{3.}] Select the channel and proceeds as follows:
\begin{enumerate}
\item[ii.] Otherwise
\begin{enumerate}
\item[a.] Get the largest entropy
\item[b.]\begin{algorithmic}
\IF {($TTL$ $>$ 0)}
\STATE  Set $PRE$ field with its $ID$; \newline
\ELSE
\STATE discard $M$
\ENDIF
\end{algorithmic}
\end{enumerate}
\end{enumerate}
\item[\textit{4.}] Each user updates the prob of each action.
\end{enumerate}
%\end{pseudocode}
\end{mdframed}
\end{document}
`