![将定理计数器设置为子节数 + 0.1?](https://linux22.com/image/429498/%E5%B0%86%E5%AE%9A%E7%90%86%E8%AE%A1%E6%95%B0%E5%99%A8%E8%AE%BE%E7%BD%AE%E4%B8%BA%E5%AD%90%E8%8A%82%E6%95%B0%20%2B%200.1%EF%BC%9F.png)
如何调整计数器,以便定理为子节 + 0.1,并且子节编号在定理之后自行调整。例如,在下面的代码中,输出产生1.1 小节其次是定理 1.1(我希望这是定理 1.2)接下来是1.2 另一个小节(我希望这个达到 1.3)。
我曾尝试使用\addcounter
,\setcounter
但没有产生预期的结果。
\documentclass{article}
\usepackage{amsthm}
\newtheorem{theorem}{Theorem}[section]
\begin{document}
\section{Test Section} some text
\subsection{subsection} blah
\begin{theorem}
How to set the theorem counter to 1.2 instead of 1.1 as in the output.
\end{theorem}
\subsection{Another subsection} How to set this counter to 1.3
\end{document}
答案1
您可以使用中描述的方法将theorem
计数器设置为计数器的别名(或重复项)subsection
从属重复计数器。
\documentclass{article}
\usepackage{amsthm}
\newtheorem{theorem}{Theorem}[section]
\makeatletter
\newcommand*{\dupcntr}[2]{%
\expandafter\let\csname c@#1\expandafter\endcsname\csname c@#2\endcsname
}
\makeatother
\dupcntr{theorem}{subsection}
\begin{document}
\section{Test Section} some text
\subsection{subsection} blah
\begin{theorem}
How to set the theorem counter to 1.2 instead of 1.1.
\end{theorem}
\subsection{Another subsection} How to set this counter to 1.3
\end{document}