0

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}

campa
  • 31,130
StarWombat
  • 11
  • 3
  • 1
    A \label refers to the last stepped counter. Within a {figure} environment, it is the \counter macro which steps the counter. Long story short: \label must come after \caption. – campa Aug 03 '22 at 11:24
  • Unrelated: don't use the center env to center inside a float. Sounds counter intuitive, but here is the issue: the float, say figure, adds space above and below its contents so does the center env. Replace \begin{center} by \centering and remove \end{center} – daleif Aug 03 '22 at 11:31
  • unrelated but I would delete \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

0 Answers0