每节图片编号仅限一节

每节图片编号仅限一节

我有一篇很长的文章,包含很多章节和图片。通常,我会按章节编号图片,

\numberwithin{figure}{section}

在一个特别大的部分中,我想使用每个子部分的数字编号。有人能帮我吗?

谢谢!

更新:

我接受了 Zarko 的回答,但我可能说得太早了。我稍微修改了提供的示例以说明我想要实现的目标(参见其中显示“错误数字”的地方):

\documentclass{article}
\usepackage[vmargin=10mm]{geometry}
\usepackage{amsmath}
\numberwithin{table}{section}
\setcounter{topnumber}{8}
\setcounter{bottomnumber}{8}
\setcounter{totalnumber}{8}

\begin{document}

\section{Long section, with subsections}
some text
\subsection{Subsection 1.1}
some text
\begin{table}[htb]
\caption{Table 1.1}
\end{table}
some text some text some text some text 
\subsection{Subsection 1.2}
some text
\begin{table}[htb]
\caption{Table 1.2}
\end{table}
some text some text some text some text  

\section{Long section, with subsections}
\numberwithin{table}{subsection}
some text
\subsection{Subsection 2.1}
some text
\begin{table}[htb]
\caption{Table 2.1.1}
\end{table}
some text some text some text some text 
\subsection{Subsection 2.2}
some text
\begin{table}[htb]
\caption{Table 2.2.1}
\end{table}
some text some text some text some text  

\section{Long section, with subsections}
\numberwithin{table}{section}
some text
\subsection{Subsection 3.1}
some text some text some text some text some text some text
\begin{table}[htb]
\caption{Table 3.1}
\end{table}
\subsection{Subsection 3.2}
some text some text some text some text some text some text 
\begin{table}[htb]
\caption{Table 3.2 - Incorrect Number}
\end{table}

\end{document}

在此处输入图片描述

答案1

欢迎来到 TeX.SE!

在您想要更改浮点数的章节标题后插入

\numberwithin{figure}{subsection}
\numberwithin{table}{subsection}

在章节标题之后,在您想要恢复编号样式的位置插入

\numberwithin{figure}{section}`
\numberwithin{table}{section}` 

例如:

\documentclass{article}
\usepackage[vmargin=10mm]{geometry}
\usepackage{amsmath}
\numberwithin{table}{section}
\usepackage{lipsum}
\setcounter{topnumber}{8}
\setcounter{bottomnumber}{8}
\setcounter{totalnumber}{8}

\begin{document}
\section{Short section}
some text some text 
\begin{table}[htb]
\caption{Table 1.1}
\end{table}
some text some text 
\begin{table}[htb]
\caption{Table 1.2}
\end{table}
some text some text some text some 

\section{Long section, with subsections}
\numberwithin{table}{subsection}
some text
\subsection{Subsection 2.1}
some text
\begin{table}[htb]
\caption{Table 2.1.1}
\end{table}
some text some text some text some text 
\subsection{Subsection 2.2}
some text
\begin{table}[htb]
\caption{Table 2.2.2}
\end{table}
some text some text some text some text  

\section{Short section}
\numberwithin{table}{section}

some text some text some text some text some text some text
\begin{table}[htb]
\caption{Table 3.1}
\end{table}
some text some text some text some text some text some text 
\end{document}

在此处输入图片描述

编辑:

不幸的是,只要以下部分(其中浮点数的编号返回到预设方式),上述解决方案就可以正常工作。在这些部分有子部分的情况下,浮点数计数器(figuretable)在每个子部分之后都会重置(如编辑问题中所述)。

克服这种故障的一种方法是使用chngcntr如下 MWE 中所示的包:

\documentclass{article}
\usepackage[vmargin=10mm]{geometry}
\usepackage{chngcntr}
\counterwithin{table}{section}  % <------
\counterwithin{figure}{section} % <------
% for enables up to 11 floats per page
\setcounter{topnumber}{11}\setcounter{bottomnumber}{11}\setcounter{totalnumber}{11}

\begin{document}
\section{Short section}
some text some text
\begin{table}[htb]
\caption{Table 1.1}
\end{table}
some text some text
\begin{table}[htb]
\caption{Table 1.2}
\end{table}
some text some text some text some

\section{Long section, with subsections}
\counterwithin{table}{subsection}  % <------
\counterwithin{figure}{subsection} % <------


\subsection{Subsection 2.1}
some text
\begin{table}[htb]
\caption{Table 2.1.1}
\end{table}
some text some text some text some text
\subsection{Subsection 2.2}
some text
\begin{table}[htb]
\caption{Table 2.2.1}
\end{table}
some text some text some text some text

\begin{table}[htb]
\caption{Table 2.2.2}
\end{table}

\section{Short section again}
\counterwithout{table}{subsection}  % <------
\counterwithout{figure}{subsection} % <------
\counterwithin{table}{section}  % <------
\counterwithin{figure}{section} % <------


\begin{table}[htb]
\caption{Table 3.1}
\end{table}
some text some text some text some text some text some text
\begin{table}[htb]
\caption{Table 3.2}

\subsection{Subsection 3.1}
\end{table}
\begin{table}[htb]
\caption{Table 3.3}
\end{table}
\begin{table}[htb]
\caption{Table 3.4}
\end{table}

\subsection{Subsection 3.2}
\begin{table}[htb]
\caption{Table 3.5}
\end{table}
\end{document}

在此处输入图片描述

相关内容