Graphics, Figures & Tables\ref and \autoref numbering figures like subsections

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
sivertz
Posts: 6
Joined: Mon May 04, 2009 7:52 pm

\ref and \autoref numbering figures like subsections

Post by sivertz »

A large document uses \ref and \autoref to link to figures. For most of the document it works fine, but in some sections, it gives links to figures with the wrong numbers. Although the Figure appears to be correctly numbered (in this case as Fig. 10.3), the \ref command calls it 10.1.2 instead. Here is the code:
...blah.blah.blah of the full survey predicts $\sim200-1000$ quasars at
$6.5<z<7.5$ (\autoref{fig:z7:quasars}); such quasars should be...

\begin{figure}
\label{fig:z7:quasars}
\begin{center}
\includegraphics[angle=0,scale=0.5]{agn/agn_census_z7_quasars.pdf}
\caption{{\it Left:} $z-y$ vs. $y$ color-magnitude diagram
\end{center}
\end{figure}

Any ideas under what conditions it can mess up in this way?

Recommended reading 2024:

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

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

Stefan Kottwitz
Site Admin
Posts: 10345
Joined: Mon Mar 10, 2008 9:44 pm

\ref and \autoref numbering figures like subsections

Post by Stefan Kottwitz »

Hi sivertz,

welcome to the board!
Use \label right after the \caption command, not before, see \label description.

Btw. inside figure environments I recommend to use \centering instead of \begin{center} ... \end{center}, see center vs. \centering. Further placement parameters for \begin{figure} like [htbp] could be useful.

Stefan
LaTeX.org admin
sivertz
Posts: 6
Joined: Mon May 04, 2009 7:52 pm

Re: \ref and \autoref numbering figures like subsections

Post by sivertz »

Thanks, Stefan_K. Moving the \label after the \caption did not solve the numbering problem. But the caption is very long. Could that be part of the problem?

Also, is there an \endcentering command? How does LaTeX know the scope
of \centering?
User avatar
Stefan Kottwitz
Site Admin
Posts: 10345
Joined: Mon Mar 10, 2008 9:44 pm

\ref and \autoref numbering figures like subsections

Post by Stefan Kottwitz »

sivertz wrote:Moving the \label after the \caption did not solve the numbering problem.
Did you compile two times to check that?
sivertz wrote:Also, is there an \endcentering command? How does LaTeX know the scope of \centering?
The scope is limited by the surrounding environment. That's why \end{figure} will end the effect of \centering. It's also possible to limit the scope by braces, like

Code: Select all

{\centering ... your text ... }
but in this case before the closing brace the paragraph should be ended by an empty line or \par.

Stefan
LaTeX.org admin
Post Reply