Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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!

share|improve this question

1 Answer 1

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}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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