[Tex/LaTex] Number of figure by chapter

numbering

I need number of figure by chapter:

I'm using this but sometimes it repeats the numeration

\usepackage{chngcntr}
\counterwithin{figure}{chapter}
\counterwithin{table}{chapter}

example:

chapter1
  figure 1.1
  figure 1.2
  figure 1.3
chapter2
  figure 2.1
 section 2.1
  figure 2.2
  figure 2.3
chapter3
  figure 3.1
  figure 3.2
 section 3.1
  figure 3.3

example:

     \documentclass{report}
\usepackage{float}
\usepackage{chngcntr}
\counterwithin{figure}{section}

\begin{document}
\chapter{}
\section{section 1.1}

\begin{figure}[H]
\centering
\rule{1cm}{1cm}% placeholder for graphic
\caption{A figure}
\end{figure}

\begin{figure}[H]
\centering
\rule{1cm}{1cm}% placeholder for graphic
\caption{A figure}
\end{figure}

\section{section 1.2}

\begin{figure}[H]
\centering
\rule{1cm}{1cm}% placeholder for graphic
\caption{A figure}
\end{figure}



\chapter{}
\section{section 2.1}

\begin{figure}[H]
\centering
\rule{1cm}{1cm}% placeholder for graphic
\caption{A figure}
\end{figure}

\end{document}

this is the screeshot:
enter image description here

Best Answer

  • Use report class when chapters are needed.
  • Remove some packages (not needed to get the output).
  • Do not include numbers in section and chapters (those are created automatically by latex)

    \documentclass{report}
    
    \usepackage{float}
    
    \begin{document}
    
    \chapter{ } %if you want a name write it as \chapter{name}
    
    
    
    \begin{figure}[H]
    \centering
        \rule{1cm}{1cm}% placeholder for graphic
    \caption{A figure}
    \end{figure}
    
    \section{}
    
    \begin{figure}[H]
    \centering
    \rule{1cm}{1cm}% placeholder for graphic
     \caption{A figure}
    \end{figure}
    
    \section{ }
    
    \begin{figure}[H]
    \centering
    \rule{1cm}{1cm}% placeholder for graphic
    \caption{A figure}
    \end{figure}
    
     \end{document}