0

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}

enter image description here

4
  • Welcome to TeX.SX! When I compile your MWE the numbering is correct... Sep 21, 2018 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? Sep 21, 2018 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... Sep 21, 2018 at 19:58
  • Yes! Using the amsmath package as suggested by @HafidBoukhoulda fixed it! Sep 21, 2018 at 20:05

2 Answers 2

2

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}

enter image description here

0

enter image description here

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}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.