65
\begin{figure} \center
    \begin{subfigure}[b]
        \includegraphics[width=60mm]{a}
        \label{fig:a}
    \end{subfigure} %

    \begin{subfigure}[b]    
        \includegraphics[width=60mm]{b}
        \label{fig:b}    
    \end{subfigure} 
    \caption{my caption}
\end{figure}

I get an error

! Missing number, treated as zero.
<to be read again>
\let
           \includegraphics
                            [width=60mm]{a}

What's wrong?

0

5 Answers 5

58

This is how you should be using it.

\documentclass{article}
\usepackage{graphicx,subfigure}
\begin{document}
\begin{figure}
\centering     %%% not \center
\subfigure[Figure A]{\label{fig:a}\includegraphics[width=60mm]{example-image-a}}
\subfigure[Figure B]{\label{fig:b}\includegraphics[width=60mm]{example-image-b}}
\caption{my caption}
\end{figure}
\end{document}

enter image description here

Note: subfigure is outdated and new one is subfig which introduces subfloat command. You may consider using subfig instead of subfigure.

3
  • 5
    This does not actually answer the questions topic, does it? The actual solution to this mismatch would be to rename the question to "How should I use subfigures?" Jan 22, 2013 at 10:09
  • 4
    @JukkaDahlbom A lot of users seem to find this question through searching for the error, and having a straightforward example of how the package should be used is likely to solve many problems. Thus, I’d leave the title as it is.
    – doncherry
    May 16, 2013 at 5:02
  • 1
    By the way, you can use \hfill between the subfigures to spread them evenly horizontally.
    – Lenar Hoyt
    Jul 15, 2014 at 15:13
22

I believe you're using the subcaption package. The problem you have is that as a second argument to \begin{subfigure} you should tell it how wide you want your figure to be; e.g.

\begin{figure} \centering
    \begin{subfigure}[b]{\linewidth}
        \includegraphics[width=60mm]{a}
        \label{fig:a}
    \end{subfigure} %

    \begin{subfigure}[b]{\linewidth}    
        \includegraphics[width=60mm]{b}
        \label{fig:b}    
    \end{subfigure} 
    \caption{my caption}
\end{figure}

If you have further problems you can refer to the package documentation.

Hope that helps!

3
  • 2
    Right, so if I understood correctly, the problem was with \begin{subfigure} missing a required argument, but LaTeX highlighted \includegraphics as the problematic area. Is it theoretically possible to write a preprocessor to spot such errors and report them properly? Aug 1, 2013 at 2:04
  • 1
    It should say: "Environment subfigure is missing required argument".
    – user877329
    Jul 25, 2015 at 8:40
  • 1
    I get confused between subcaption and subfigure regularly as they have different numbers of arguments for the open environment. Thanks :)
    – Aaron
    Dec 13, 2018 at 12:53
2

This answer is based on this Overleaf article

The subfigure package is long outdated, and will generate a 'Missing number' error when there is no error present. This will generate an error, as the subfigure package does not recognise \textwidth as a number, when it is in fact a number (equivalent to the constant width of the total text block on a page). The way to resolve this is to use the more updated subcaption package, which has replaced subfigure.

The above Overleaf article also provides several other possible causes of the error- "Missing number, treated as zero."

Note: Although this answer addresses the same error, i.e., "Missing number, treated as zero.", but caused by different reasons than the original question. However, I believe the answer will be useful to the community as it addresses the issue in general which is use of sufigure package. Moreover, people usually search the error given by latex not the cause. Had the cause of error known to them, they need not search it on google. LOL

0

The missing number is the desired width of the subfigure. Change \begin{subfigure}[b] to \begin{subfigure}[b]{60mm} as proposed by @jlfranco.

0

Maybe you can try to write the label under the \subfigure level, not at the same level.

Right demo work for me:

\begin{figure}[htbp]
\centering
\subfigure[Bearings vibration]{
    \includegraphics[width=5.5cm]{figures}
    }
\quad
\subfigure[Wheel treads vibration]{
    \includegraphics[width=5.5cm]{figures.png}
}
\quad
\subfigure[Rotatory speed]{
    \includegraphics[width=5.5cm]{figures}
\label{fig:label13}} % difference in this line
\caption{examples}\label{fig:label1} 
\end{figure}

Wrong demo not work for me:

\begin{figure}[htbp]
\centering
\subfigure[Bearings vibration]{
    \includegraphics[width=5.5cm]{figures}
    }
\quad
\subfigure[Wheel treads vibration]{
    \includegraphics[width=5.5cm]{figures.png}
}
\quad
\subfigure[Rotatory speed]{
    \includegraphics[width=5.5cm]{figures}
}\label{fig:label13} % difference in this line
\caption{examples}\label{fig:label1} 
\end{figure}

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.