0

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?

Chen Ji
  • 1
  • 1

1 Answers1

0

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 enter image description here

Finally the complete code and the result:

enter image description here

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 1]{\fakeimage} \qquad
        \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 1]{\fakeimage} \qquad
        \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 1]{\fakeimage} \qquad
    \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 1]{\fakeimage} \qquad
    \subfigure[fig 2]{\fakeimage} 
    \caption{For section}
\end{figure}
\section{the section}
\begin{figure}[h!]
    \centering
    \subfigure[fig 1]{\fakeimage} \qquad
    \subfigure[fig 2]{\fakeimage} 
    \caption{For section}
\end{figure}
\end{document}
J Leon V.
  • 11,533
  • 16
  • 47
  • 1
    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 02 '18 at 04:29
  • 1
    Your approach requires the author to issue potentially lots of \renewcommand{\thefigure}{...} directives. Is there a way to automate your numbering system? – Mico Apr 02 '18 at 04:31
  • Well, that is what I can suggest in the short time I have, and yes, it is necessary to automate and maybe there is an effective method, which thanks to your observation can be solved here. – J Leon V. Apr 02 '18 at 04:42
  • Why \subfigure at all? –  Apr 02 '18 at 05:03