我使用 按节对图表进行编号\counterwithin
。但是,图表的编号不是 1.1、1.2、2.1、2.2 等,而是 11、12、21、22 等。有没有办法重新插入小数点?
以下是 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}
答案1
使用\numberwithin{figure}{section}
来自数学包裹
\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}
答案2
您提供的代码运行良好。看起来您的完整代码修改了\thefigure
序言中某处的定义。您可以使用\renewcommand{\thefigure}{\arabic{section}.\arabic{figure}}
as 方法来明确重新定义\thefigure
图形标签在由 LaTeX 排版时的表示形式。这里,section
是部分计数器,figure
是图形计数器。
\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}