General\ref gives section number instead of figure or table number

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
gbravo
Posts: 3
Joined: Tue Jan 23, 2007 2:56 pm

\ref gives section number instead of figure or table number

Post by gbravo »

Hi all.

Does anybody know why sometimes it happens that a \ref command produces a reference to the section number even if the corresponding \label is inserted in a table or figure environment?
This happens especially when I'm using the hyperref package, but I'm not sure if there's a connection. I'm using Miktex 2.4.1461.

Thank you,
Giangiacomo

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

User avatar
pumpkinegan
Posts: 91
Joined: Thu May 03, 2007 10:29 pm

\ref gives section number instead of figure or table number

Post by pumpkinegan »

I experienced something similar. The solution was to make sure that you put the \label in the right part of the environment (whether it is equation, figure, or table).

You have to ensure that \label comes last. For example:

Code: Select all

\begin{table}
	\centering
		\begin{tabular}
			
		\end{tabular}
	\caption{Table caption.}
	\label{tab:xxxx}
\end{table}
or

Code: Select all

\begin{figure}
	\centering
		\includegraphics{}
	\caption{Figure caption.}
	\label{fig:xxxx}
\end{figure}
Patrick.
User avatar
countbela666
Posts: 64
Joined: Thu Apr 26, 2007 2:44 pm

\ref gives section number instead of figure or table number

Post by countbela666 »

As Patrick has already said it is fundamental to put your label after the caption command. This is because a label always refers to the last counter which has been changed before. If you invert the sequence of caption and label, you always refer to that point in your document where the last counter has been changed--which will mostly be the last section or chapter command--as in that case the caption command changes the counter of the figure environment you want to refer to after the label has been set.

Regards
Marcel
Listen to me children of the night, beyond the doors of darkness you will find
a thousand worlds for you to see here, take my hand and follow me...
Post Reply