# Per section figure numbering - reset counter each section

I would like to achieve book like figure numbering for my article class document. MWE:

\documentclass[11pt,a4paper]{article}
\usepackage{graphicx}

% optionally - this creates: Figure 1.1 ... Figure 2.2
%\renewcommand{\thefigure}{\arabic{section}.\arabic{figure}}

\begin{document}

\section{first section}

\begin{figure}[h]
\centering
\includegraphics[width=\textwidth]{1.png}
\caption{figure 1.1} % should be 1.1
\end{figure}

\section{second section}

\begin{figure}[h]
\centering
\includegraphics[width=\textwidth]{1.png}
\caption{figure 2.1} % should be 2.1 - actually is 2 or 2.2 with optional code
\end{figure}

\end{document}


I do not want to reset the counter manually on each section.

This is easily achieved using \numberwithin from the amsmath package.

\documentclass[11pt,a4paper]{article}
\usepackage{graphicx}
\usepackage{amsmath}
\numberwithin{figure}{section}

\begin{document}
\section{first section}

\begin{figure}[h]
\centering
\rule{4cm}{4cm}  % replace with image
\caption{figure 1.1}
\end{figure}

\section{second section}

\begin{figure}[h]
\centering
\rule{4cm}{4cm}  % replace with image
\caption{figure 2.1}
\end{figure}
\end{document}


• One could also use the chngcntr package; it defines a \counterwithin command, that does the same as \numberwithin and a \counterwithin* command that doesn't prefix the figure number with the section number/. Il also defines \counterwithout and \counterwithout* commands, that do the reverse. – Bernard Sep 29 '14 at 21:41
• I am seeing a lot of solutions for implementing section wise figure numbers but none for continuous numbering through sections. I never had this problem before. Something must have changed in the MacTeX distribution which made section wise numbering a default. – cryptic0 Feb 13 '19 at 16:31
• @cryptic0 --- As far as I know, the default in the standard document classes is continuous numbering in article and per chapter in report and book. It's unlikely that this has changed in in the last quarter century or so. It's not difficult to adjust the behaviour in either direction, but how you do it may depend on the document class. I suggest posting a new question if you need help with this. – Ian Thompson Feb 14 '19 at 21:46