# Format per section numbering of figures and tables

I'm number figures and tables by section using \counterwithin. However, instead of numbering the figures 1.1, 1.2, 2.1, 2.2, etc., they are getting numbered 11, 12, 21, 22, etc. Is there a way to reinsert the decimal?

Here is a MWE:

\documentclass{article}

\usepackage{float}
\counterwithin{figure}{section}

\begin{document}

\section{foo}

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

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

\section{foo2}

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

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

\end{document}


• Welcome to TeX.SX! When I compile your MWE the numbering is correct... – Phelype Oleinik Sep 21 '18 at 19:47
• @Phyelype Yes, from all the documentation, it appears that it should be numbering that way (with the decimals) by default. Are you aware of any way to modify the default formatting that I could potentially use to force it? – Jake Thompson Sep 21 '18 at 19:54
• It would be best to see that code that is changing the default behavior, rather than trying to run over it. Anyhow, the figure number is, in standard situations, given by the \thefigure macro, so you could try \makeatletter\def\thefigure{\thesection.\@arabic\c@figure}\makeatother... – Phelype Oleinik Sep 21 '18 at 19:58
• Yes! Using the amsmath package as suggested by @HafidBoukhoulda fixed it! – Jake Thompson Sep 21 '18 at 20:05

Using \numberwithin{figure}{section} from the amsmath package

\documentclass{article}

\usepackage{amsmath,float}

\numberwithin{figure}{section}

\begin{document}

\section{foo}

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

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

\section{foo2}

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

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

\end{document}


The code you provided works well. It looks like your full code modifies the definition of \thefigure somewhere in the preamble. You can use \renewcommand{\thefigure}{\arabic{section}.\arabic{figure}} as means to explicitly redefine \thefigure which is the representation of the figure label when it is typeset by LaTeX. Here, section is the section counter and figure is the figure counter.

\documentclass{article}

\usepackage{float}
\counterwithin{figure}{section}
\renewcommand{\thefigure}{\arabic{section}.\arabic{figure}}

\begin{document}

\section{foo}

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

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

\section{foo2}

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

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

\end{document}