### LaTeX: Wrong figure numbers in subfloat

Tuesday, August 4 2009, 16:14
I've been puzzled by some incorrect figure numbers in my LaTeX document recently. I have a figure, 2, with two subfigures, 2a and 2b, but when referencing them, I get figures 1a and 1b.
It turned out you have to put the \label commands in the correct order, like so:
\begin{figure}[b]  \caption{Detail of cameras on a Nokia N95 smartphone}  \label{fig:cameras}  \centering  \subfloat[User camera located above screen]{    \label{fig:user_camera}    \includegraphics{images/front_camera.png}}  \hspace{2cm}  \subfloat[Perspective camera on backside of device]{    \label{fig:perspective_camera}    \includegraphics{images/back_camera.png}}\end{figure}
Also, make sure that \caption always precedes \label as Luke Maciak suggests.
Note that as Matthias mentions in the comments below, you may have to put the \caption and \label after the \subfloats. I haven't determined yet when one or the other should be done, but just remember that moving them around may resolve your problem.
Rating:
Actions:
 Matthias: Thanks for your post! I had a similar... Post reply Show 2 comments Graham: Matthias- that has allowed me to heave a...