![Numeração de figuras por seção - zerar o contador de cada seção](https://rvso.com/image/298803/Numera%C3%A7%C3%A3o%20de%20figuras%20por%20se%C3%A7%C3%A3o%20-%20zerar%20o%20contador%20de%20cada%20se%C3%A7%C3%A3o.png)
Eu gostaria de obter numeração de figuras semelhante a um livro para meu documento de classe de artigo. 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}
Não quero zerar o contador manualmente em cada seção.
Responder1
Isto é facilmente conseguido usando \numberwithin
a partir dopacote amsmath.
\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}