# how to number the figure into the subsection level (such as figure 1.1.1,1.1.2)? [duplicate]

I used the following codes to achieve numbering the figure in section level like (1.1, 1.2...):

\usepackage{amsmath}
\numberwithin{figure}{section}


Then I can got the first figure in the first section is 1.1, the second figure in the second section is 1.2... but if there is a figure in subsection(1.2) in section 1, how to change the first figure label from 1.1 to 1.1.1?

## marked as duplicate by Henri Menke, user31729, Mico, TeXnician, Stefan PinnowApr 2 '18 at 6:47

• \numberwithin{figure}{subsection}? – Zarko Apr 2 '18 at 3:41
• This is definitely a duplicate. This question has been asked a hundred times before. – Henri Menke Apr 2 '18 at 5:15

I think the numbering of images should be according to the chapters, but well, everything is possible in latex, to achieve what you want you just have to redefine the format of the figures counter \thefigure, the problem is that you must redefine it for each environment, here the code:

Standard format:

\renewcommand{\thefigure}{\arabic{chapter}.\arabic{figure}}

Format for sections:

\renewcommand{\thefigure}{\arabic{chapter}.\arabic{section}.\arabic{figure}}


For the following chapters you must redefine the standard if you do not want the following error to occur

Finally the complete code and the result:

code:

% arara: pdflatex: {synctex: yes, action: nonstopmode}

\documentclass{scrreprt}
\usepackage{booktabs,caption}
\usepackage{graphicx}
\usepackage{subfigure}
\newcommand{\fakeimage}{{\fboxsep=-\fboxrule\fbox{\rule{0pt}{2.5cm}\hspace{3cm}}}}
\begin{document}
\chapter{chapter one}

\begin{figure}[h!]
\centering
\subfigure[fig 2]{\fakeimage}
\caption{fig for chapter}
\end{figure}
\renewcommand{\thefigure}{\arabic{chapter}.\arabic{section}.\arabic{figure}}
\section{the section}
\begin{figure}[h!]
\centering
\subfigure[fig 2]{\fakeimage}
\caption{For section}
\end{figure}
%for chapter Two you have to redefine \thefigure to the original
\renewcommand{\thefigure}{\arabic{chapter}.\arabic{figure}}
\chapter{Chapter two}
\begin{figure}[h!]
\centering
\subfigure[fig 2]{\fakeimage}
\caption{fig for chapter}
\end{figure}
\renewcommand{\thefigure}{\arabic{chapter}.\arabic{section}.\arabic{figure}}
\section{the section}
\begin{figure}[h!]
\centering
\subfigure[fig 2]{\fakeimage}
\caption{For section}
\end{figure}
\section{the section}
\begin{figure}[h!]
\centering

• The subfigure package has been deprecated for a long time by now. Please consider rewriting your answer using the machinery of either the subfig or the subcaption caption. – Mico Apr 2 '18 at 4:29
• Your approach requires the author to issue potentially lots of \renewcommand{\thefigure}{...} directives. Is there a way to automate your numbering system? – Mico Apr 2 '18 at 4:31
• Why \subfigure at all? – user31729 Apr 2 '18 at 5:03