Tuesday, February 26, 2008

LaTex: Fixing Wrong Figure Numbers

LaTex: Fixing Wrong Figure Numbers

The post is copied from: Terminally Incoherent


What I tell you right now may save you hours of extensive debugging, cursing under your breath, commenting out custom code dealing with figure layout and much frustration. Whenever you use figures, always (and I mean ALWAYS EVER FOREVER ALWAYS) put \caption first, and \label second like this:



\begin{figure}[htp]
\centering
\includegraphics{image.eps}
\caption{Some Image}
\label{fig:some-image}
\end{figure}
If you put the \label above \caption you will run into trouble when referencing figures inside subsections. In my case, the caption underneath the figure would say Fig. 4.2 but the output of \ref would be 4.3.10 because somehow it was picking up the section numbers wrong.

I had to submit the document today n all chapters except chapter 1 had \label above \caption n i was so *&^*&%^&$%* but i found on google search a blog Terminally Incoherent. It helped me n i m really thankful to the owner of the blog.

Blogged with Flock

38 comments:

Anonymous said...

Thanks a lot for the post! It saves me time :)

Unknown said...

Me too! The default way TeXnicCenter creates a figure is the very way that creates this problem. I guess I'll be contacting the developers.

Anonymous said...

Thanks a million! I was about to resort to entering table numbers manually.

Anonymous said...

Wonderful!, i was breaking my head where the problem was. Thank you so much.

Anonymous said...

Thanks very much for the post, i was starting to bang my head on the table...
I also want to mention that when using centered figures, the \labe{} should be after \caption but before \end{center}.

Anonymous said...

Thanks so much! TexnicCenter can really be frustrating some times..

Anonymous said...

Thanks! You solved my problem!

Anonymous said...

Thanks man! I have almost torn off all my hair before I found your blog.

Anonymous said...

Nice! Manually entering numbers will not the task my friend has to face all thanks to you :)

Anonymous said...

Thanks a lot! I am one hour away from sending my thesis out and I was going nots on this one. Wish you a beer!

Anonymous said...

Thanks a lot : )

Neamat El Tazi said...

Thank you so much.. I can't tell you how much I wonaa thank you. I've been trying to correct these wrong numbers for about 6 hours and I was going nuts. These were the only thing left to finish my thesis and I've finished writing now because of your post.. Thank you.. Thank you.. Thank you

Slasher said...

Thank you very much. I just had the problem and was very confused. In my case I had caption before a table, then the table and then the label. That didnt work either. When I moved the label after the caption but before the table it was correct.

Troutinator said...

Thanks for the tip, I couldn't figure out why my numbers were wrong in the \ref{}. Still think its strange that you have to put the label after the caption as I put the label right after \begin{table} to make them easier to identify.

NoJ said...

This is huge!
Thanks for the hint, as I already spent a couple of hours trying to figure out why my figures are sometimes mislabeled.

Anonymous said...

Thanks!!!! Much appreciated post!!!

John J. Camilleri said...

Just what I was looking for, thanks so much! As Richard said the default TeXnicCenter template does this incorrectly, you always just assume those things are the correct way of doing things...

Anonymous said...

Thanks dude!

Vesal said...

THANK YOU! THANK YOU! THANK YOU! And thanks to google for finding your post.

Anonymous said...

Thanks indeed for this post. Now my figure references don't all say "figure 5".

Anonymous said...

My hero

Anonymous said...

You saved me hours of frustration. Amazing. I never would have thought of moving the caption and label around to fix the problem. You are probably some sort of god or something. Can I shine your shoes?

Anonymous said...

This is EXACTLY what I was looking for. These kinds of small things can be a complete pain in the ...

Thanks!

Anonymous said...

I'm glad this post is still up--it saved me a LOT of time. Thank you!!

JM Albornoz said...

Thank you dude, you're the MacDaddy!

Emma said...

thanks! very helpful indeed.

Anonymous said...

Thanks! 5 seconds of reading saving n+ minutes of debugging ;)

Anonymous said...

Thanks! A nice succinct solution to what I was having trouble with.

Anonymous said...

Thanks a lot! So much time saved.

Anonymous said...

Thaaaaaaaaaaanks :)

Bir said...

Tons of thanks !! :)
I had gone crazy because of this.
Your post came like a blessing!!

Anonymous said...

THANK YOU.

Anonymous said...

Wow! Thank you so much. This has saved me many hours of debugging :)

Anonymous said...

Thank you very much. It's 2013 now and you are still saving people!

Anonymous said...

Thanks.
One of the reasons why a lot of people don't like Latex: it has its own personality :-)

Unknown said...
This comment has been removed by the author.
Renzo said...

Thank you very much. Saved me a lot of time!

Emil Jonasson said...

I LOVE THIS, it fixed all my figure numbering problems!