6

I want to make a figure consisting of two subfigures. Having read the Wikipedia subentry on subfloats, I tried to follow it exactly, so I did not use the subfig or subfigure package, only the caption and subcaption packages. Nevertheless, I am getting a Missing number, treated as zero error, pointing to the line with \begin{subfigure}.

What am I doing wrong?

Below is my code:

% In preamble:
\usepackage{url}
\usepackage{graphicx}
\usepackage{caption}
\usepackage{subcaption}
\usepackage{rotating}
\usepackage[table]{xcolor}
\usepackage{multirow}
\usepackage{amsfonts}


% In document:
\begin{figure}[htpb]
\begin{subfigure}[b]{width=0.45\textwidth}
\centering
\includegraphics[width=\textwidth]{img_a}
\end{subfigure}
\begin{subfigure}[b]{width=0.45\textwidth}
\centering
\includegraphics[width=\textwidth]{img_b}
\end{subfigure}
\caption{A caption.}
\label{fig:my-figure}
\end{figure}

I am using TeXShop 2.47 on Mac OS X 10.8.1 (x86_64).

Thanks!

9

Note that the includegraphics command has syntax width=<width>, but the subfigure environment just has \begin{subfigure}{width}, not as width=<width>

I loaded the graphicx package with the demo option just for demonstration- remove it when you're working on your actual document :)

\documentclass{article}
% In preamble:
\usepackage[demo]{graphicx}
\usepackage{caption}
\usepackage{subcaption}


\begin{document}
% In document:
\begin{figure}[htpb]
    \begin{subfigure}[b]{0.45\textwidth}
        \centering
        \includegraphics[width=\textwidth]{img_a}
    \end{subfigure}
    \begin{subfigure}[b]{0.45\textwidth}
        \centering
        \includegraphics[width=\textwidth]{img_b}
    \end{subfigure}
    \caption{A caption.}
    \label{fig:my-figure}
\end{figure}

\end{document}
  • 1
    Thanks a lot, it took me a long time to figure out that I was using the width argument and this was making my tex crash ! – Cedric May 2 at 13:31
0

Maybe the problem is that the name of your file contains an underscore ("_"). We had the same problem and it was fixed changing the name of the file.

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.