main
members
work
about me
avatar
Paul(admin)
post

LaTeX: Wrong figure numbers in subfloat

Post replyCan't edit post
Watch topicCan't delete post
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:Post replyWatch topic
avatar
Matthias (guest)
comment
Saturday, August 15 2009, 1:16
Can't edit commentCan't delete comment
Thanks for your post!
I had a similar problem: several figure environments which of each contained several subfloats. Even when I had my code in your order, it was wrong: e.g. figure1 had 2 subfloats and figure2 with 3.
Then, it referenced figure1 correctly as fig. 1, but the subfloats as 2a and 2b, then figure2 correctly as fig.2, but its subfloats as 3a, 3b and 3c.
I don't know whats wrong with the package but it obviously needs a lot of debugging to be done!
And now the solution: put the caption and the label of the figure AFTER the subfigures. Do it with both. And: caption first...
avatar
Graham (guest)
comment
Monday, November 9 2009, 19:21
Can't edit commentCan't delete comment
Matthias- that has allowed me to heave a sigh of relief after a *lot* of head-scratching.
Thanks!
Post reply Hide comments

More updates

Click here to read more news items.
Members have extra privileges. You can login or register.
© 2005–2017 P. F. Lammertsma
No members currently online; 558 hits today by 181 unique users