Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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.

share|improve this question
    
Are you okay with a non-floating algorithm? –  Werner Jul 1 '12 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 –  pythonee Jul 1 '12 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 '12 at 2:58
add comment

marked as duplicate by Werner, Marco Daniel, egreg, cmhughes, percusse Jul 17 '12 at 13:45

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

1 Answer

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.

See the discussion in this answer for details.

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.

share|improve this answer
    
I prefer to use standard towcolumn option. But I don't know how to switch to onecolumn for certain part of document –  pythonee Jul 1 '12 at 11:46
    
\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. –  Frank Mittelbach Jul 1 '12 at 12:29
    
thank you for your reply. I have tried this method. But I got some break line issue. so I switch to multicol package. It breaks well. so finally I decide to use package multicol. and It is very convenient switch column. –  pythonee Jul 1 '12 at 13:52
add comment

Not the answer you're looking for? Browse other questions tagged or ask your own question.