我正在尝试局部修改定理环境的编号。基本思想是先有定理 1,然后是定理 2A、引理 2B、引理 2C,然后再回到定理 3、引理 4 等。MWE 的输出更准确、更简洁地解释了这一点:
- 如何这应该实现吗?理想情况下,该解决方案还将与 MWE 中列出的未注释的软件包一起使用。
平均能量损失
\documentclass[12pt]{book}
%\usepackage[estonian]{babel}
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{thmtools}
\usepackage{mathtools}
%\usepackage{tocloft}
%\usepackage{titlesec}
%\usepackage{hyperref}
\declaretheorem[numberwithin=chapter,style=plain,name=Theorem,refname={theorem, theorems},Refname={Theorem,Theorems}]{myTheorem} %defining myTheorem
\declaretheorem[name=Lemma,refname={lemma, lemmas},Refname={Lemma,Lemmas},sibling=myTheorem]{myLemma} %defining myLemma
\declaretheorem[name=Sentence,refname={sentence,sentences},Refname={Sentence,Sentences},sibling=myTheorem] {mySentence} %defining mySentence
\begin{document}
\chapter{Test Chapter}
This is an example part of a large document.
\section{Test Section}
\subsection{Test Subsection}
Some statements, normal behaviour.
\begin{myTheorem}
This numbering is OK.
\end{myTheorem}
\begin{mySentence}
This numbering is OK.
\end{mySentence}
Now three similar statements. How to make local change in numbering for the following three instances of different environments?
\begin{myLemma}
This should be 1.3a.
\end{myLemma}
\begin{myLemma}
This should be 1.3b.
\end{myLemma}
\begin{mySentence}
This should be 1.3c.
\end{mySentence}
Again different statements. Back to normal behaviour.
\begin{myTheorem}
This should be 1.4.
\end{myTheorem}
\begin{myLemma}
This should be 1.5.
\end{myLemma}
\end{document}
我发现的最接近的解决方案是这个答案经过贡萨洛·梅迪纳针对这个问题用字母对定理进行编号,但不改变其他定理的编号。然而,天真地改变这个答案是行不通的。它没有效果,可能是因为其中一个包更改了计数器名称。
答案1
一个简单的解决方案:
subequations
复制来自的定义amsmath
- ...但要小心确保你修改
\the<counter>
了受影响的每个环境 $
\documentclass[12pt]{book}
%\usepackage[estonian]{babel}
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{thmtools}
\usepackage{mathtools}
\usepackage{tocloft}
\usepackage{titlesec}
\usepackage{hyperref}
\declaretheorem[numberwithin=chapter,style=plain,name=Theorem,refname={theorem, theorems},Refname={Theorem,Theorems}]{myTheorem} %defining myTheorem
\declaretheorem[name=Lemma,refname={lemma, lemmas},Refname={Lemma,Lemmas},sibling=myTheorem]{myLemma} %defining myLemma
\declaretheorem[name=Sentence,refname={sentence,sentences},Refname={Sentence,Sentences},sibling=myTheorem] {mySentence} %defining mySentence
\makeatletter
\newcounter{myparentThm}
\newenvironment{mysubtheorems}{%
\refstepcounter{myTheorem}
\protected@edef\themyparentThm{\themyTheorem}%
\setcounter{myparentThm}{\value{myTheorem}}%
\setcounter{myTheorem}{0}%
\def\themyTheorem{\themyparentThm\alph{myTheorem}}%
\def\themyLemma{\themyparentThm\alph{myLemma}}%
\def\themySentence{\themyparentThm\alph{mySentence}}%
\ignorespaces
}{%
\setcounter{myTheorem}{\value{myparentThm}}%
\ignorespacesafterend
}
\makeatother
\begin{document}
\listoftheorems
\chapter{Test Chapter}
This is an example part of a large document.
\section{Test Section}
\subsection{Test Subsection}
Some statements, normal behaviour.
\begin{myTheorem}
This numbering is OK.
\end{myTheorem}
\begin{mySentence}
This numbering is OK.
\end{mySentence}
\begin{mysubtheorems}
Now three similar statements. How to make local change in numbering for the following three instances of different environments?
\begin{myLemma}
This should be 1.3a.
\end{myLemma}
\begin{myLemma}
This should be 1.3b.
\end{myLemma}
\begin{mySentence}\label{test:sentence}
This should be 1.3c.
\end{mySentence}
\end{mysubtheorems}
Again different statements. Back to normal behaviour.
\begin{myTheorem}
This should be 1.4.
\end{myTheorem}
\begin{myLemma}
This should be 1.5.
\end{myLemma}
\end{document}
输出:
$这与 OP 观察到的原因有关梅迪纳的回答不起作用。简单地说amsthm
,当您定义兄弟计数器时,您得到的是直接使用兄弟计数器的定理。更准确地说,当您调用时\newtheorem{theorem}[equation]{Theorem}
,中的代码\begin{theorem}
将\refstepcounter{equation}
,并且在打印定理编号时它将调用\theequation
。
这被 改变了thmtools
(我认为cleveref
),因为 cref 类型的命令通过将计数器名称映射到其表示来工作。在 的情况下,当您使用兄弟计数器时,例如,在代码中thmtools
使用 的定义,您将得到myLemma
myLemma
具有与 相同的底层计数寄存器的计数器myTheorem
,- 各种支持宏包括
\themyLemma
设置为等于\themyTheorem
via\let
, - 以及
myLemma
使用计数器myLemma
和格式访问其数字的环境\themyLemma
。
因此,为了让事情正常运作thmtools
,你需要
- 代码来交换计数器值(这与 Medina 在链接答案中的内容基本相同,也是所做的
subequations
) - 对于每个受影响的环境,替换相应的代码
\the<env>
(因为它们是通过复制的\let
,所以更改一个并不会改变所有)。
注意:我还没有完全测试与 hyperref 的兼容性。如果存在问题,可以通过\theH<env>
适当更改定义来解决;请参阅手册的附录 A.3.2 thmtools
。
答案2
盯着 thmtools 代码看了很久之后,我想我找到了一种方法来做到这一点。这个想法是暂时中止有问题的定理计数器(类似于 thmtools 的continues
键),\the<theorem>
根据需要重新定义。为了对命令\letteringtheorems
和之间的每个定理执行此操作\stopletteringtheorems
,我们使用钩子。具体来说,我们使用带有标签的内核钩子来添加到现有的 thmtools 中,preheadhook
因为这允许我们稍后使用 删除添加的代码\RemoveFromHook
。thmtools 命令\addtotheorempreheadhook
等没有这样的删除对应项。由于我们只想要紧随 之后的定理的数量\letteringtheorems
,我们使用\AddToHookNext
来存储该数字。
从一些非常基本的测试来看,它似乎与hyperref
和配合得很好\listoftheorems
。不过,不保证它不会破坏其他东西。
\documentclass[12pt]{book}
\usepackage{amsthm}
\usepackage{thmtools}
\usepackage{hyperref}
\declaretheorem[numberwithin=chapter,style=plain,name=Theorem,refname={theorem, theorems},Refname={Theorem,Theorems}]{myTheorem} %defining myTheorem
\declaretheorem[name=Lemma,refname={lemma, lemmas},Refname={Lemma,Lemmas},sibling=myTheorem]{myLemma} %defining myLemma
\declaretheorem[name=Sentence,refname={sentence,sentences},Refname={Sentence,Sentences},sibling=myTheorem] {mySentence} %defining mySentence
\makeatletter
\newcounter{thmletter}
\newcommand{\letteringtheorems}{%
\AddToHookNext{cmd/thmt@generic@preheadhook/before}{%
\refstepcounter{\thmt@envname}%
\xdef\tempcounterval{\csname the\thmt@envname\endcsname}%
}%
\AddToHook{cmd/thmt@generic@preheadhook/after}[thmletters]{%
\@xa\let\csname c@\thmt@envname\endcsname\c@thmt@dummyctr%
\@xa\let\csname theH\thmt@envname\endcsname\theHthmt@dummyctr%
\stepcounter{thmletter}%
\@xa\def\csname the\thmt@envname\endcsname{\tempcounterval\alph{thmletter}}%
}%
}
\newcommand{\stopletteringtheorems}{%
\RemoveFromHook{cmd/thmt@generic@preheadhook/after}[thmletters]%
\setcounter{thmletter}{0}%
}
\makeatother
\begin{document}
\chapter{Test Chapter}
This is an example part of a large document.
\section{Test Section}
\subsection{Test Subsection}
Some statements, normal behaviour.
\begin{myTheorem}
This numbering is OK.
\end{myTheorem}
\begin{mySentence}
This numbering is OK.
\end{mySentence}
Now three similar statements. How to make local change in numbering for the following three instances of different environments?
\letteringtheorems
\begin{myLemma}[label=abc]
This should be 1.3a.
\end{myLemma}
\begin{myLemma}[label=bla]
This should be 1.3b.
\end{myLemma}
\begin{mySentence}
This should be 1.3c.
\end{mySentence}
\stopletteringtheorems
Again different statements. Back to normal behaviour.
\begin{myTheorem}
This should be 1.4.
\end{myTheorem}
\begin{myLemma}[label=hfd]
This should be 1.5.
\end{myLemma}
\begin{myLemma}
This should be 1.6.
\end{myLemma}
\listoftheorems
\end{document}