2

I am a latex newbie! I just wanted to place a figure in my two column document, I used multicol package but when I want to insert a figure in middle of text I get this Error:

! Missing number, treated as zero.

I used many ways, most of them were sophisticated and I did not figure out what they actually did but none of them were useful. So I ask my question here and hope to get help from you guys! Thanks

by the way, This is part of my code I've problem with:

\documentclass[a4paper]{article}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{wasysym}
\usepackage[labelfont=bf]{caption}
\usepackage[margin={1cm,1cm}]{geometry}
\usepackage{multicol,lipsum,graphicx,float}
\begin{document}
\begin{multicols*}{2}
\begin{figure}[!h]
\centering{\includegraphics[width=7cm]{fig3.png}}
\caption{
this is caption
}
\end{figure}
\end{multicols}
3
  • 3
    I don't see the "missing number treated as zero" when I compile your MWE. On the other hand, I do so the warning "Package multicol Warning: Floats and marginpars not allowed inside `multicols' environment!." – user30471 Aug 17 '16 at 1:02
  • 1
    not central to the question -- \centering does not take an argument. it's essentially a "switch" that is in effect until the end of the current environment, which must end with a paragraph break for the effect to be reliable. (the figure environment by default ends with a paragraph break, but has other problems here, as explained in another comment.) – barbara beeton Aug 17 '16 at 1:31
  • I used same picture but a different caption(because previous caption has formulas and I thought maybe that's the problem) but this time the compilation process ends without significant warning except there was no figure in the text. – David Aug 17 '16 at 9:21
1

As commented by Andrew, multicols does not allow floating environments. As you are trying to force the figure to be exactly at this position with [!h] you may as well just use a center environment instead. To put a caption on this, replace the \caption command by

\captionof{figure}{...}

The \captionof command is defined by the caption package which you are already loading.

Sample output

\documentclass[a4paper]{article}

\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{wasysym}
\usepackage[labelfont=bf]{caption}
\usepackage[includeheadfoot,margin={1cm,1cm}]{geometry}
\usepackage{multicol,lipsum,graphicx,float}

\begin{document}

\begin{multicols*}{2}
  \lipsum[1]
  \begin{center}
    \centering\includegraphics[width=7cm]{example-image-a.png}
    \captionof{figure}{this is caption}
  \end{center}
  \lipsum[2-8]
\end{multicols*}

\end{document}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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