# IEEE-Template: Algorithm over both columns

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?

-
Welcome to TeX.SE. It is always best to compose a fully compilable MWE that illustrates the problem including the \documentclass and the appropriate packages so that those trying to help don't have to recreate it. This will also serve as a test case and ensure that the solution actually works for you. –  Peter Grill May 8 '12 at 19:11

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

\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):

\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.

-
Great, thanks. But when I but this inside a \begin{figure} ... then it won't work anymore?!? –  Chris May 8 '12 at 19:21
@Chris: I've added a float restyling. Note that you have to use \begin{figure*} ... \end{figure*} and not just \begin{figure} ... \end{figure}. –  Werner May 8 '12 at 19:30
When I use \begin{figure*} with options [h!] or [htb], it puts the image very far from its place in source, usually on the last page. When I try the option [H] it does not produce any output. Is there anyway to force Latex to typeset this single column image closer to its actual place? –  Aydin Nov 7 '12 at 12:56
can I make it self-customized? say make it as wide as 1.5 columns effectively Thanks! –  Sibbs Gambling Sep 9 '13 at 15:29
@perfectionm1ng: I see you've asked a new question. –  Werner Sep 9 '13 at 15:46