[Tex/LaTex] Counter reset for numbering the figure

counterssectioning

In my chapter, I have several sections.
How can I reset the counter of figures for each section?

i.e. In chapter 1, section 1, My figures should be numbered 1,2,3 (instead of 1.1, 1.2, 1.3).
In section 2, my figures numbering should restart and they should be numbered 1,2,3 as well (instead of 1.4, 1.5, 1.6).

Best Answer

You can do the following. But as already mentioned in my comment, this seems like a bad idea to me. Are you really sure you want to do this?

\counterwithin{figure}{section}
\renewcommand\thefigure{\arabic{figure}}

To undo this effect you can use:

\counterwithout{figure}{section}
\renewcommand\thefigure{\thechapter.\arabic{figure}}

A complete example (which also shows the problematic behaviour of it):

\documentclass[]{report}

\usepackage[]{graphicx}

\counterwithin{figure}{section}
\renewcommand\thefigure{\arabic{figure}}

\begin{document}
\chapter{Foo}
\section{Bar}
\begin{figure}% >>>
  \centering
  \includegraphics{example-image-duck}%
  \caption
    {%
      duck1%
      \label{fig:duck1}%
    }%
\end{figure}% <<<

\section{Baz}
\begin{figure}% >>>
  \centering
  \includegraphics{example-image-duck}%
  \caption
    {%
      duck2%
      \label{fig:duck2}%
    }%
\end{figure}% <<<
\end{document}
Related Question