![每部分圖形編號 - 重置每部分計數器](https://rvso.com/image/298803/%E6%AF%8F%E9%83%A8%E5%88%86%E5%9C%96%E5%BD%A2%E7%B7%A8%E8%99%9F%20-%20%E9%87%8D%E7%BD%AE%E6%AF%8F%E9%83%A8%E5%88%86%E8%A8%88%E6%95%B8%E5%99%A8.png)
我想為我的文章類文檔實現像書一樣的圖形編號。微量元素:
\documentclass[11pt,a4paper]{article}
\usepackage{graphicx}
% optionally - this creates: Figure 1.1 ... Figure 2.2
%\renewcommand{\thefigure}{\arabic{section}.\arabic{figure}}
\begin{document}
\section{first section}
\begin{figure}[h]
\centering
\includegraphics[width=\textwidth]{1.png}
\caption{figure 1.1} % should be 1.1
\end{figure}
\section{second section}
\begin{figure}[h]
\centering
\includegraphics[width=\textwidth]{1.png}
\caption{figure 2.1} % should be 2.1 - actually is 2 or 2.2 with optional code
\end{figure}
\end{document}
我不想在每個部分手動重置計數器。
答案1
\numberwithin
使用以下命令可以輕鬆實現這一點數學包。
\documentclass[11pt,a4paper]{article}
\usepackage{graphicx}
\usepackage{amsmath}
\numberwithin{figure}{section}
\begin{document}
\section{first section}
\begin{figure}[h]
\centering
\rule{4cm}{4cm} % replace with image
\caption{figure 1.1}
\end{figure}
\section{second section}
\begin{figure}[h]
\centering
\rule{4cm}{4cm} % replace with image
\caption{figure 2.1}
\end{figure}
\end{document}