Monday, September 26, 2011

Latex - Fixing wrong figure numbers

I didn't think I would write this kind of posts so early in my blog life, but if you happen to be a LateX user, you might thank me some day. 


I just added a couple of figures to a document within the subfigure environment (i.e. I wanted the graphs to be within the same figure, and next to each other). Curiously enough, even though it was compiling correctly, the numbers of the subfigures were right, but the number of the main figure wasn't. Under the figures it said Figure 1, but when I made a reference to it in the text it would say Figure 5 (!!!!). Luckily there is Google. And people that write about it. So here is what you should ALWAYS do:

put \caption first, \label second. 

I am borrowing the guy's nice code illustration just for you:


\begin{figure}[htp]
 	\centering
 		\includegraphics{image.eps}
 	\caption{Some Image}
 	\label{fig:some-image}
\end{figure}
I did, and all my referencing problems were solved. 5 min! I even decided to write this post. Hope it will be helpful for someone else one day as well.

No comments: