LaTeX 计数器:如何在每次 \subsubsection 后重置计数器
"{" 你可以使用 LaTeX 中的 \newcounter 命令创建一个计数器 testcounter,并使用 \setcounter 命令将其初始值设置为 1。然后,在每次调用 \subsubsection 之前,使用 \setcounter 命令将 testcounter 的值重置为 1。"} "{" "} "{" 下面是一个示例代码:"} "{" "} "{" latex\"\} \"{\" \\documentclass{article}\"\} \"{\" \"\} \"{\" \\newcounter{testcounter}\"\} \"{\" \\setcounter{testcounter}{1}\"\} \"{\" \"\} \"{\" \\begin{document}\"\} \"{\" \"\} \"{\" \\subsubsection{Section 1}\"\} \"{\" This is subsection \\thetestcounter. % 输出 1\"\} \"{\" \\stepcounter{testcounter}\"\} \"{\" \"\} \"{\" \\subsubsection{Section 2}\"\} \"{\" This is subsection \\thetestcounter. % 输出 2\"\} \"{\" \\stepcounter{testcounter}\"\} \"{\" \"\} \"{\" \\subsubsection{Section 3}\"\} \"{\" This is subsection \\thetestcounter. % 输出 3\"\} \"{\" \\stepcounter{testcounter}\"\} \"{\" \"\} \"{\" \\setcounter{testcounter}{1} % 重置 testcounter 的值为 1\"\} \"{\" \"\} \"{\" \\subsubsection{Section 4}\"\} \"{\" This is subsection \\thetestcounter. % 输出 1\"\} \"{\" \\stepcounter{testcounter}\"\} \"{\" \"\} \"{\" \\subsubsection{Section 5}\"\} \"{\" This is subsection \\thetestcounter. % 输出 2\"\} \"{\" \\stepcounter{testcounter}\"\} \"{\" \"\} \"{\" \\end{document}\"\} \"{\" "} "{" "} "{" 编译上述代码后,你将得到以下输出:"} "{" "} "{" \"\} \"{\" Section 1\"\} \"{\" This is subsection 1.\"\} \"{\" \"\} \"{\" Section 2\"\} \"{\" This is subsection 2.\"\} \"{\" \"\} \"{\" Section 3\"\} \"{\" This is subsection 3.\"\} \"{\" \"\} \"{\" Section 4\"\} \"{\" This is subsection 1.\"\} \"{\" \"\} \"{\" Section 5\"\} \"{\" This is subsection 2.\"\} \"{\" "} "{" "} "{" 每次调用 \subsubsection 后,计数器 testcounter 的值会自动增加 1。当你希望重置计数器 testcounter 的值为 1 时,只需使用 \setcounter 命令重新设置即可。"}
原文地址: https://www.cveoy.top/t/topic/p798 著作权归作者所有。请勿转载和采集!