# How to insert algorithm inside multicols environment [duplicate]

Possible Duplicate:
Placing figures inside a two-column document

Here is my MWE:

\documentclass{article}

\usepackage{multicol}
\usepackage{algorithm}
\usepackage{algpseudocode}
\usepackage{lipsum}

\begin{document}
\title{How to insert algorithm inside multicols environment}
\author{pythonee}
\date{}

\maketitle

\begin{abstract}
\lipsum[1-2]
\end{abstract}

\begin{multicols*}{2}
\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}

\end{multicols*}

\end{document}


It output the warning message when I compile this:

Package multicol Warning: Floats and marginpars not allowed inside multicols'
environment!.


And the pseudocode is missing.

Can you tell me how to insert single column float algorithm environment. I don't want algorithm* style.

• Are you okay with a non-floating algorithm?
– Werner
Jul 1, 2012 at 2:18
• @Werner basically, I really want floating algorithm. As I have tried to add [H] parameter into algorithm. but there leave much blank space Jul 1, 2012 at 2:31
• This problem can be generalized in terms of placing a float inside the multicols environment. For that, Frank's answer in Placing figures inside a two-column document should provide a solution, however minimal, and one could consider this question a duplicate.
– Werner
Jul 1, 2012 at 2:58

The multicols environment doesn't support floats that are column wide, for the simple reason that this would conflict with balancing and with the fact that you could alter the number of columns on a single page.
Given that your example uses multicols* for the whole document the first thing you need to decide for yourself is: do you need to use multicol at all or would it be better to use LaTeX's standard twocolumnpossibilities.
However, as Werner remarked I actually recently implemented a unsupported extension to multicol that offers placing column figures within the scope of the environment. They do not automatically "float" but you can specify that they should appear on a certain page in a certain column position. See here for details.
• \onecolumn ends the current page and restarts with a single column page. \twocolumn ends the current page and restarts with two columns. \twocolumn[some single column text]` does the same but keeps the material in brackets in single column at the top of the page. Jul 1, 2012 at 12:29