I'm running into trouble with numbering figures - the actual figures have a caption with numbers that increment 1, 2, 3, etc. But the references to them within the text are using section numbers (2.1, 7.3, etc). A bit of googling suggests this is related to setting \numberwithin{figure}{section} somewhere, which I haven't done explicitly, so I'm guessing the offending command is lurking in a package I've called. I just don't know which one.
Can anyone identify the offending package please, and/or give an example of how to override this so that the figure numbers in the captions and the text are the same? Thank you in advance. I'm attaching a MWE below, which produces the labels 1 and 2 on the figures themselves, but references them as figures 2 and 3.1 respectively.
\documentclass[12pt]{article}
\title{Title of this}
\author{Me}
\date{\today}
\usepackage{pgf,pgfarrows,pgfnodes,pgfautomata,pgfheaps,pgfshade}
\usepackage{amsmath,amssymb}
\usepackage[latin1]{inputenc}
\usepackage{colortbl}
% or whatever
\usepackage{mathptmx}
\usepackage{helvet}
\usepackage{courier}
\usepackage{txfonts}
\usepackage[english]{babel}
\usepackage{csquotes}
\usepackage[T1]{fontenc}
\begin{document}
\maketitle
\section{First section}
First section, with no figures to illustrate the point.
\section{Second section}
Here is fig.~\ref{fig:AAA}
\begin{figure}[h!]\label{fig:AAA}
\begin{center}
\includegraphics[width=0.5\textwidth]{figure1.png}
\caption{caption}
\end{center}
\end{figure}
\section{Third section}
This is the third section
\subsection{A subsection}
Here is fig.~\ref{fig:BBB}
\begin{figure}[h!]\label{fig:BBB}
\begin{center}
\includegraphics[width=0.7\textwidth]{figure2.png}
\caption{Another caption.}
\end{center}
\end{figure}
\bibliographystyle{abbrv}
\bibliography{main}
\end{document}
\labelrefers to the last stepped counter. Within a{figure}environment, it is the\countermacro which steps the counter. Long story short:\labelmust come after\caption. – campa Aug 03 '22 at 11:24centerenv to center inside a float. Sounds counter intuitive, but here is the issue: the float, sayfigure, adds space above and below its contents so does thecenterenv. Replace\begin{center}by\centeringand remove\end{center}– daleif Aug 03 '22 at 11:31\usepackage[latin1]{inputenc}and then save your file (as it is posted to this site) in UTF-8 – David Carlisle Aug 03 '22 at 11:56