0

I want my figures to be captioned Figure x.n for the nth figure in chapter x. The below MWE gives correct figure numbers in the captions, but \ref gives the chapter numbers instead of x.y:

\documentclass{scrbook}

\usepackage{chngcntr}

\counterwithin{figure}{chapter}

\newcommand{\myfig}[3]
{
    \begin{figure}[ht]
        \label{#1}
        \centering
        %\input{figures/#2}
        \caption{#3}
    \end{figure}
}

\begin{document}

\chapter{Chapter One}

\myfig{figone}{foo}{This is the first figure.}
\myfig{figtwo}{foo}{This is the second figure.}

\chapter{Chapter Two}

\myfig{figthree}{foo}{This is the third figure.}

\chapter{Chapter Three}

See figures \ref{figtwo} and \ref{figone} and \ref{figthree}.

\end{document}

I expected Chapter Three to contain

See figures 1.2 and 1.1 and 2.1.

Instead it contains

See figures 1 and 1 and 2.

How do I reference figures to get x.n numbering?

lockstep
  • 250,273
spraff
  • 1,501

0 Answers0