13

I am trying to insert a figure with a caption into a multicol article. When the figure was inserted on its own, it was fine: includegraphics[width=0.5cm]{image}

However, when I tried to insert the caption [see below], the caption did not appear anywhere in the article and the figure disappeared.

\documentclass{article}
\usepackage[hmarginratio=1:1,top=30 mm,columnsep=20pt,hmargin=2.5cm]{geometry}
\usepackage[font=it]{caption}
\usepackage{paralist}
\usepackage{multicol}
\usepackage{setspace}
\usepackage{graphicx}

\begin{document}
\begin{multicols}{2}
text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text

\begin{figure}[h!] 
\caption{Fig.1 xxxxx}
\includegraphics[width=0.5cm]{image}
\end{figure}

text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text

\end{multicols}
\end{document}

What might be the issue and how could I fix it?

Werner
  • 603,163
xuan
  • 321

2 Answers2

19

Note the warning issues by multicol:

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

One way around this is to not make your floats float. The float package provides the [H] float specifier which avoids this:

enter image description here

\documentclass{article}
\usepackage[hmarginratio=1:1,top=30 mm,columnsep=20pt,hmargin=2.5cm]{geometry}% http://ctan.org/pkg/geometry
\usepackage[font=it]{caption}% http://ctan.org/pkg/caption
\usepackage{multicol,lipsum,graphicx,float}% http://ctan.org/pkg/{multicol,lipsum,graphicx,float}

\begin{document}
\begin{multicols}{2}
\lipsum[1-2]

\begin{figure}[H]
\caption{This is a caption}
\includegraphics[width=0.5cm]{example-image-a}
\end{figure}

\lipsum[3-4]
\end{multicols}
\end{document}

example-image-a was taken from the mwe package, while lipsum provided dummy text, Lorem ipsum style.

Werner
  • 603,163
  • 1
    I found so many not-working-well solutions, but your hint with the [H] really was it! thanks so much. – Gerwald Mar 22 '15 at 20:26
7

One option is to avoid floats altogether. You can use capt-of package to get the captions.

\documentclass[twocolumn]{article}
\usepackage{graphicx}
\usepackage{lipsum}
\usepackage{capt-of}%%To get the caption

\begin{document}
\lipsum[1-5]
\begingroup
    \centering
    \includegraphics[width=2cm]{example-image-a}
    \captionof{figure}{This is the caption}\label{fig:a}
\endgroup
From figure~\ref{fig:a} we get nothing.

\lipsum[6-8]

\end{document}

enter image description here