Graphics, Figures & Tablesfigure label not correct

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
neumannturing
Posts: 32
Joined: Sun Mar 01, 2009 8:29 am

figure label not correct

Post by neumannturing »

Hello,
I use \numberwithin{figure}{section} at the header. But later when I label and refer a figure (using \label{} and \ref{}). The number does not show up correctly.
For example, all figures in section 3 show up as 3 in the reference. What is the problem? Thank you.

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
gmedina
Posts: 2313
Joined: Wed Jul 11, 2007 11:45 pm

figure label not correct

Post by gmedina »

Hi,

please post a minimal working example that allows us to reproduce the odd behaviour mentioned.
1,1,2,3,5,8,13,21,34,55,89,144,233,...
neumannturing
Posts: 32
Joined: Sun Mar 01, 2009 8:29 am

Re: figure label not correct

Post by neumannturing »

Minimal example:
\documentclass[12pt]{amsart}
\usepackage{graphicx}
\numberwithin{figure}{section}
\begin{document}
\section{introduction}
\section{example}
Problem is here Fig.~\ref{fig:3}. But It should be 2.1
\begin{figure}[hbt]\label{fig:3}
\includegraphics[scale=0.5]{triTri}
\caption{$p$ is a vertex of $\O$.}
\end{figure}
\end{document}
User avatar
gmedina
Posts: 2313
Joined: Wed Jul 11, 2007 11:45 pm

figure label not correct

Post by gmedina »

Hi,

in float environments such as figure and table, the \label command should always go after the \caption command. Example:

Code: Select all

\documentclass[12pt]{amsart}

\numberwithin{figure}{section}

\begin{document}

\section{introduction}
\section{example}
Problem solved. Fig.~\ref{fig:3} produces the expected value.
\begin{figure}[!hbt]
  \centering
  \rule{5cm}{3cm}% just to simulate an actual figure
  \caption{$p$ is a vertex of $\O$.}
  \label{fig:3}
\end{figure}

\end{document}
Please notice that I used a black rectangle to simulate an actual figure and make the example compilable for everyone.
1,1,2,3,5,8,13,21,34,55,89,144,233,...
neumannturing
Posts: 32
Joined: Sun Mar 01, 2009 8:29 am

Re: figure label not correct

Post by neumannturing »

Just as gmedi's post.
Post Reply