Thmtools 示例和解决方案环境与其他环境共享编号

Thmtools 示例和解决方案环境与其他环境共享编号

回答以下问题这个问题,我使用该包定义了示例和解决方案环境thmtools,我希望与文档中的其他环境共享编号。这是我的 MWE:

\documentclass{book}
 \usepackage[margin=.75 in]{geometry}
\usepackage[english = american]{csquotes}
\usepackage{amsmath,amsfonts,amssymb,amsthm,color,srcltx,enumitem,bm,cancel,thmtools}
\usepackage{setspace}
\usepackage{titlesec}
\newcommand{\sectionbreak}{\clearpage}

%Plain environments:
\theoremstyle{plain}
\newtheorem{theorem}{Theorem}[section]
\newtheorem{corollary}[theorem]{Corollary}
\newtheorem{lemma}[theorem]{Lemma}
\newtheorem{proposition}[theorem]{Proposition}
\newtheorem{result}[theorem]{Result}
%Definition environments:
\theoremstyle{definition}
\newtheorem{definition}[theorem]{Definition}
%Remark environments:
\theoremstyle{remark}
\newtheorem{remark}[theorem]{Remark}

%Example and solution environments (from https://tex.stackexchange.com/questions/19947/example-solution-environment):
\declaretheoremstyle[
spaceabove=6pt, spacebelow=6pt,
headfont=\normalfont\bfseries,
notefont=\mdseries, notebraces={(}{)},
bodyfont=\normalfont,
postheadspace=1em,
numberwithin=section,
sharenumber=theorem
]{exstyle}
\declaretheoremstyle[
spaceabove=6pt, spacebelow=6pt,
headfont=\normalfont\bfseries,
notefont=\mdseries, notebraces={(}{)},
bodyfont=\normalfont,
postheadspace=1em,
headpunct={},
qed=$\blacktriangleleft$,
numbered=no,
sharenumber=theorem
]{solstyle}
\declaretheorem[style=exstyle]{example}
\declaretheorem[style=solstyle]{solution}

\begin{document}
\part{Part 1}
\chapter{Chapter 1}
\section{Section 1}
\begin{definition}
Definition goes here
\end{definition}
\begin{theorem}
Theorem goes here
\end{theorem}
\begin{proposition}
Proposition goes here
\end{proposition}
\begin{lemma}
Lemma goes here
\end{lemma}
\begin{result}
Result goes here
\end{result}
\begin{example}
Example goes here
\end{example}
\end{document}

请注意sharenumber=theorem,我添加了一个来自thmtools文档问题是,添加此行会导致 LaTeX 错误“缺少 \begin{document}”。删除此行sharenumber=theorem可消除错误,但共享编号会丢失。

答案1

numberwithin=section首先,在 的声明中无需使用,extstyle因为example环境旨在与 共享相同的计数器theorem。并且theoremsection根据其定义在 内进行了编号。此外,numberwithinkey\declaretheoremstyle对 来说是未知的。key 也是如此sharenumber。此 key 应传递给 ,\declaretheorem而不是\declaretheoremstyle

  1. 不要把sharenumbernumberwithin放在里面\declaretheoremstyle

  2. 放入。sharenumber\declaretheorem

现在是完整的代码。

\documentclass{book}
 \usepackage[margin=.75 in]{geometry}
\usepackage[english = american]{csquotes}
\usepackage{amsmath,amsfonts,amssymb,amsthm,color,srcltx,enumitem,bm,cancel,thmtools}
\usepackage{setspace}
\usepackage{titlesec}
\newcommand{\sectionbreak}{\clearpage}

%Plain environments:
\theoremstyle{plain}
\newtheorem{theorem}{Theorem}[section]
\newtheorem{corollary}[theorem]{Corollary}
\newtheorem{lemma}[theorem]{Lemma}
\newtheorem{proposition}[theorem]{Proposition}
\newtheorem{result}[theorem]{Result}
%Definition environments:
\theoremstyle{definition}
\newtheorem{definition}[theorem]{Definition}
%Remark environments:
\theoremstyle{remark}
\newtheorem{remark}[theorem]{Remark}

%Example and solution environments (from http://tex.stackexchange.com/questions/19947/example-solution-environment):
\declaretheoremstyle[
spaceabove=6pt, spacebelow=6pt,
headfont=\normalfont\bfseries,
notefont=\mdseries, notebraces={(}{)},
bodyfont=\normalfont,
postheadspace=1em,
%numberwithin=section,              %%<--- remove this as it is unknown here
]{exstyle}
\declaretheoremstyle[
spaceabove=6pt, spacebelow=6pt,
headfont=\normalfont\bfseries,
notefont=\mdseries, notebraces={(}{)},
bodyfont=\normalfont,
postheadspace=1em,
headpunct={},
qed=$\blacktriangleleft$,
numbered=no,
%sharenumber=theorem     %% not needed here
]{solstyle}
\declaretheorem[sharenumber=theorem,style=exstyle]{example}
\declaretheorem[style=solstyle]{solution}

\begin{document}
\part{Part 1}
\chapter{Chapter 1}
\section{Section 1}
\begin{definition}
Definition goes here
\end{definition}
\begin{theorem}
Theorem goes here
\end{theorem}
\begin{proposition}
Proposition goes here
\end{proposition}
\begin{lemma}
Lemma goes here
\end{lemma}
\begin{result}
Result goes here
\end{result}
\begin{example}
Example goes here
\end{example}
\end{document}

在此处输入图片描述

您还可以使用sibling=theoremnumberlike=theorem

相关内容