[Tex/LaTex] putting algorithm in box

algorithmsboxesframed

Below is my code snippet. Please help me to put a framed box in my algorithm.

\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[i.] Receives the utility.
        \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}

Best Answer

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

enter image description here

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[i.] Receives the utility.
        \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}