Friday, March 20, 2009

Properly labeling Tables and Figures in Latex

As with all things in Latex; it can be done, but it might not make sense.

If you have tables and figures throughout your document you might come across the problem that your \ref{} command considers tables and figures the same thing and therefore gives the wrong number. For instance if your document has tables and figures appearing in the following order

Table 1
Table 2
Figure 1

and you try to reference Figure 1 you might actually get a "3" instead of "1." This happens if you label your figures and tables wrong. To avoid this always make sure the \label{} is AFTER the \caption{} for both tables and figures. That should make everything work fine.




konrad said...

Thank you, I had exactly this problem and your advice solved it!

Travis McBride said...

Yes, thank you! I was tearing my hair out with a couple of tables for my thesis until I found your blog. Placing the label in the right place made my references work correctly. :-)

Travis McBride said...

Thank you! I was tearing my hair out with two tables for my thesis. I could not understand why my references to the labels for each were not resolving correctly. It's all about placement within the table block! :-)