# Subfloat with subcaption package: Missing number, treated as zero

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!

-

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}

-