0

My problem is that every time I write \caption in a figure, the preceding number increases its value in one unit. Nevertheless, I'd like to group them as in sections. For example, instead of 1,2,3,etc. I'd like 1.1,1.2,2.1,etc. The class of document I'm using is an article.

Thank you for your responses.

Josemi
  • 266
  • I don't mind about tables or equations, I just want to change the numeration in figures. On the other hand, the class is an article, I'll edit my question and add this information. – Josemi Feb 04 '19 at 18:21
  • 1
    Try this \usepackage{amsmath} and \numberwithin{figure}{section} – Hafid Boukhoulda Feb 04 '19 at 18:54

2 Answers2

1

Previously the answer would be to use the changecntr package but that facility is now part of basic LaTeX; however texdoc changecntr presents the original package manual (at least on my installation).

In your preamble put

\counterwithin{figure}{section} % for figures to be numbered within sections
% \counterwithin{table}{section} % for tables to be numbered within sections
Peter Wilson
  • 28,066
1

Using \numberwithin macro from amsmath package

\documentclass[]{article}
\usepackage{amsmath}
\numberwithin{figure}{section}

\usepackage{lipsum,mwe} 

\title{My nice article}
\author{me}
\begin{document}
\maketitle
\section{my first section}
\lipsum[1]
\begin{figure}
    \centering
    \includegraphics{example-image-a}
    \caption{image-a}
    \label{fig:my_labela}
\end{figure}
\lipsum[2]
\begin{figure}
    \centering
    \includegraphics{example-image-b}
    \caption{image-b}
    \label{fig:my_labelb}
\end{figure}

\section{my second section}
\lipsum[3]
\begin{figure}
    \centering
    \includegraphics{example-image-c}
    \caption{image-c}
    \label{fig:my_labelc}
\end{figure}
\lipsum[4]
\begin{figure}
    \centering
    \includegraphics{example-image-a}
    \caption{image-d}
    \label{fig:my_labeld}
\end{figure}

\end{document}