[Tex/LaTex] How to float figure within multicol text

floatsgraphicsmulticol

I have a simple two-column text, and want to place figures within the text. I used this code

\documentclass{article}
\usepackage{multicol}
\usepackage{graphicx}
\usepackage{caption}

\begin{document}
\begin{multicols}{2}
First text
\begin{center}
    \includegraphics[width=0.5\textwidth]{ebooks.jpg}
    \captionof{figure}{This is a test}
    \label{fig: 11}
\end{center}
Second text
\end{multicols}
\end{document}

My problem is that the figure will be placed exactly after First text no matter where it is. For example, if First text needs 80% space and figure needs 30%; figure will be pushed to the second page, and we will have 20% gap in the first page.

How can I make the structure flexible. In this example, put 70% of First text in the first page (with 30% space needed for figure to make 100% filled page); then, flow the remaining 10% of First text to the second page.

Best Answer

There are a couple of possibilities here. For two-column text in the article class, you don't need the multicols environment other than to balance the columns at the end, or if you want to switch to single-column and back without incurring a page break. Just pass the twocolumn option to article. In that case, using the figure environment will indeed give you a single-column floating figure (that will usually appear at the top of the next column, but you can tweak the positioning if you need to).

Second, if you truly need the multicols environment, then the package documentation states that single-column floats are incompatible with multicols. You can use the starred forms (figure* or table*) which will take up a full page width, as @Frg points out. As it turns out, positioning floats is very complicated, and made even more so in the multi-column case. See for instance this document, which documents some of the challenges involved; both this document and the multicol package were written by Frank Mittelbach, who is heavily involved in the LaTeX3 effort, so I'd guess that if multicol doesn't support floats yet, it's still not a solved problem :)

Finally, you can abandon flexibility, and resort to trial-and-error: move the content you wish to float around in your source, and recompile and try again until it looks good. If this is your only viable approach, I'd suggest waiting until the surrounding text has mostly stabilized, so you don't waste time perfecting a layout that will just break with the next edit...

Related Question