[Tex/LaTex] IEEE-Template: Algorithm over both columns

algorithmsfloatsieeetrantwo-column

I'm currently working on a paper using the IEEEtran template. I do have a pseudocode I would like to put into this paper. In a former paper I saw that it is possible to put this algorithm in a box which is in a figure and fills up both columns of the paper. I want to do it the same way, however, I was not able to manage it.

Could anyone help me out please?

Best Answer

You are most likely referring to the use of the starred float variant:

enter image description here

\documentclass{IEEEtran}
\usepackage{algorithm}% http://ctan.org/pkg/algorithms
\usepackage{algpseudocode}% http://ctan.org/pkg/algorithmicx
\usepackage{lipsum}% http://ctan.org/pkg/lipsum
\begin{document}
\section{A section}
\begin{algorithm*}
  \caption{Euclid’s algorithm}\label{euclid}
  \begin{algorithmic}[1]
    \Procedure{Euclid}{$a,b$}\Comment{The g.c.d. of a and b}
      \State $r\gets a\bmod b$
      \While{$r\not=0$}\Comment{We have the answer if r is 0}
        \State $a\gets b$
        \State $b\gets r$
        \State $r\gets a\bmod b$
      \EndWhile\label{euclidendwhile}
      \State \textbf{return} $b$\Comment{The gcd is b}
    \EndProcedure
  \end{algorithmic}
\end{algorithm*}

\lipsum[1-15]% dummy text
\end{document}

The above MWE uses algorithmicx and algorithm that provides the algorithm pseudocode presentation. However, you can place the algorithm inside a figure environment as well. Not sure what the journal might restrict in terms of package usage.

Note that using "one column" floats in a "two column" document usually leads to undesired placement. For one, they will end up at the top by default (unless you use dblfloatfix), and usually the page after they are inserted (making first-page presentation difficult). See Wide figures in two-column documents on the UK TeX FAQ.


Here's a version that does not use algorithm, but instead restyles the figure floating environment to box its contents (thanks to float):

enter image description here

\documentclass{IEEEtran}
\usepackage{algpseudocode}% http://ctan.org/pkg/algorithmicx
\usepackage{lipsum}% http://ctan.org/pkg/lipsum
\usepackage{float}% http://ctan.org/pkg/float
\floatstyle{boxed} % Box...
\restylefloat{figure}% ...figure environment contents.
\begin{document}
\section{A section}
\begin{figure*}
  \caption{Euclid’s algorithm}\label{euclid}
  \begin{algorithmic}[1]
    \Procedure{Euclid}{$a,b$}\Comment{The g.c.d. of a and b}
      \State $r\gets a\bmod b$
      \While{$r\not=0$}\Comment{We have the answer if r is 0}
        \State $a\gets b$
        \State $b\gets r$
        \State $r\gets a\bmod b$
      \EndWhile\label{euclidendwhile}
      \State \textbf{return} $b$\Comment{The gcd is b}
    \EndProcedure
  \end{algorithmic}
\end{figure*}

\lipsum[1-15]% dummy text
\end{document}

lipsum provided some dummy text.

Related Question