The multicol
environment is not designed to support column floats. The concept of balancing makes this next to impossible to automatically provide correct results in the general case and therefore I decided not to extend multicol
in this direction for 2e.
For example, with multicol
you can change the number of columns mid-page, how should that reflect on float placements, given that TeX can't re-break prargraphs so that they flow around floats that then not fit the column width any longer.
For the less general case, e.g., fixed 2-column layout with only a little bit of balancing, one could probably extend multicol
to support this, but it would then break in the more generic cases, and as I said it isn't there.
Update
Having said the above, I couldn't resist the challenge to implement at least a trivial implementation of this. The idea is simple: we offer a command that takes 3 arguments: a page number, a column number, and a float body, e.g.
\multicolfloat{1}{2}{\centering
\includegraphics{cat.eps}
\captionof{figure}{A test}
}
The above is using \captionof
from the caption
package as this isn't really a float so \caption
would complain unless it gets modified which I didn't do.
This command can be used inside a multicols
environment and asks for this float to be placed on top column 2 on page 1. So a lot of manual work if the amount of text is changing or the multicols
environment is moved. This could be done differently and better, but that is more than I had time for.
So here is the code and a test file, a mixture of patching some hooks into multicol
and implementing the new functionality as a LaTeX3 property list.
\begin{filecontents}{multicol-floats.sty}
% Author Frank Mittelbach, 2012, License LPPL
%
% Providing column floats for multicol (proto-type implementation)
%
% Document Interface:
%
% \multicolfloat <page-num> <col-num> <float-body>
%
% To be used inside a multicols environment.
% Can only place floats on full pages not balanced pages.
% Should probably be an environment but didn't do that this time around.
%
% Subject to change and ... No support :-)
\RequirePackage{etoolbox}
\RequirePackageWithOptions{multicol}
% Patching multicol to get a few hooks in as needed
\patchcmd{\multi@column@out}%
{\setbox\count@ \vsplit\@cclv to\dimen@}%
{\create@split@column \count@ \dimen@}%
{\typeout{*** SUCCESS ***}}{\typeout{*** FAIL ***}}
\patchcmd{\multi@column@out}
{\setbox\mult@rightbox \vsplit\@cclv to\dimen@}
{\create@split@column \mult@rightbox \dimen@}
{\typeout{*** SUCCESS ***}}{\typeout{*** FAIL ***}}
\patchcmd\endmulticols
{\output}{\mc@check@unset@floats\output}
{\typeout{*** SUCCESS ***}}{\typeout{*** FAIL ***}}
\newcount\mc@column
\patchcmd\process@cols
{\relax}{\relax\mc@column\@ne}
{\typeout{*** SUCCESS ***}}{\typeout{*** FAIL ***}}
\patchcmd\process@cols
{\advance}{\advance\mc@column\@ne\advance}
{\typeout{*** SUCCESS ***}}{\typeout{*** FAIL ***}}
% Implementation of new functionality
\RequirePackage{xparse}
\ExplSyntaxOn
\DeclareDocumentCommand \multicolfloat { m m m }
{
\mc_float:nnn {#1} {#2} {#3}
}
% Implementation
\cs_generate_variant:Nn \prop_gpop:NnNT { NxNT }
\cs_generate_variant:Nn \prop_get:NnNTF { NxNTF }
\prop_new:N \__g_mc_float_prop
\tl_new:N \__l_mc_float_tl
\cs_new:Npn \mc_float:nnn #1#2#3 {
% safe a float body under the property key "page,col"
% if there already exist a float, combine them
\prop_get:NxNTF \__g_mc_float_prop {#1,#2} \__l_mc_float_tl
{
\prop_gput:Nno \__g_mc_float_prop {#1,#2}
{\__l_mc_float_tl
\vskip \floatsep
\vbox{\hsize\columnwidth #3}
}
}
{
\prop_gput:Nnn \__g_mc_float_prop {#1,#2}
{\vbox{\hsize\columnwidth #3}}
}
}
\cs_new:Npn \create@split@column #1#2 {
% look up any saved floats for current page and current column and if they exist
% add them to the to the top of box 255 and then split off a column
\prop_gpop:NxNT \__g_mc_float_prop
{\thepage, \the\mc@column }
\__l_mc_float_tl
{
\vbox_set:Nn \c_two_hundred_fifty_five
{ \__l_mc_float_tl
\vskip \textfloatsep
\vbox_unpack_clear:N \c_two_hundred_fifty_five
}
}
\vbox_set_split_to_ht:NNn #1 \c_two_hundred_fifty_five {#2}
}
\cs_new:Npn \mc@check@unset@floats {
% if the property list is not empty we haven't typeset all floats for some reason
% give error message and a display of the property list content (crude ... but there you go)
\prop_if_empty:NF \__g_mc_float_prop
{ \PackageError{xmulticol}{Unset~ column~ floats,~ details~ below}
{ }
\prop_show:N \__g_mc_float_prop
\prop_gclear:N \__g_mc_float_prop
}
}
\ExplSyntaxOff
\end{filecontents}
\documentclass{article}
\usepackage{lipsum,caption,graphicx}
\usepackage{multicol-floats}
\begin{document}
\begin{multicols}{2}
\multicolfloat{1}{1}{TEST 1-1}
\multicolfloat{1}{2}{\centering
\includegraphics{cat.eps}
\captionof{figure}{A test}
}
\multicolfloat{1}{2}{TEST \captionof{figure}{Another test}}
\multicolfloat{2}{1}{TEST 2-1}
\lipsum %\lipsum
\end{multicols}
\end{document}
As a result one gets the following output on the first page with the three floats placed in column one and two:

With only one \lipsum
in the test file, the multicols
ends on the next page and thus the float for page 2 column one isn't typeset and we get the following error message as well:
! Package xmulticol Error: Unset column floats, details below.
See the xmulticol package documentation for explanation.
Type H <return> for immediate help.
...
l.136 \end{multicols}
?
The property list \__g_mc_float_prop contains the pairs (without outer
braces):
> {2,1} => {\vbox {\hsize \columnwidth TEST 2-1}}.
<recently read> }
l.136 \end{multicols}
Not really great :-) but then this is just a proto-type anyway. In fact, if a multicols
environment starts in the middle of a page then the float will appear on the top of the column of the multicol not at the top of the page. After all, the column sizes might differ, So that is rather a feature not a bug ... hey anything on this is a feature as I said totally unsupported in this shape --- enjoy nevertheless
You can't put a floating object inside a minipage
, but you can place minipage
s inside a floating object. I notice that you are using the obsolete subfigure
package; you should use subfig
or subcaption
instead.
Below there are two approaches; the first one using the subfig
package, and the other one using the subcaption
package:
\documentclass{article}
\usepackage[demo]{graphicx}
\usepackage{caption}
\usepackage{subfig} % Needs subfig for this example.
\begin{document}
\begin{figure}
\begin{minipage}{.48\textwidth}
\centering
\subfloat[]{\includegraphics[width=.4\linewidth]{fig1}}\quad
\subfloat[]{\includegraphics[width=.4\linewidth]{fig2}}
\caption{First figure with two subfigures}
\label{fig:testa}
\end{minipage}\hfill
\begin{minipage}{.48\textwidth}
\centering
\subfloat[]{\includegraphics[width=.4\linewidth]{fig3}}\quad
\subfloat[]{\includegraphics[width=.4\linewidth]{fig4}}
\caption{Second figure with two subfigures}
\label{fig:testb}
\end{minipage}
\end{figure}
\end{document}

\documentclass{article}
\usepackage[demo]{graphicx}
\usepackage{caption}
\usepackage{subcaption}
\begin{document}
\begin{figure}
\begin{minipage}{.48\textwidth}
\centering
\subcaptionbox{}{\includegraphics[width=.4\linewidth]{fig1}}\quad
\subcaptionbox{}{\includegraphics[width=.4\linewidth]{fig2}}
\caption{First figure with two subfigures}
\label{fig:testa}
\end{minipage}\hfill
\begin{minipage}{.48\textwidth}
\centering
\subcaptionbox{}{\includegraphics[width=.4\linewidth]{fig3}}\quad
\subcaptionbox{}{\includegraphics[width=.4\linewidth]{fig4}}
\caption{Second figure with two subfigures}
\label{fig:testb}
\end{minipage}
\end{figure}
\end{document}

The demo
option for graphicx
simply replaces actual figures with black rectangles; do not use that option in your actual document.
Best Answer
Here is one way, but there are many options. Note the use of
%
characters to prevent spurious spaces from causing overfull\hbox
warnings.