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?
\labelmust come after\caption. The issue is not related to the use of thechngcntrpackage. – Mico Jul 05 '17 at 16:31\refstepcounterand\labelgrabs this information in order to provide the reference value – Jul 05 '17 at 17:53