使用 thmtools 继续具有枚举项的定理类环境

使用 thmtools 继续具有枚举项的定理类环境

以下分述三项议题:

  1. 我怎样才能让“1.1 示例(一些示例),续”中的枚举列表在与标题/注释相同的行上开始其项目“2。...”,就像原始的 1.1 示例(一些示例)一样?
  2. 如何消除定理声明\hspace{-1.5pt}键值中的临时错误?如果没有它,在后续部分中,标题“1.1 示例”和注释“(一些示例)”之间确实有大约 1.5 个额外的水平空间。nameexscont
  3. 为什么需要\savenum/ \backnumruse 来恢复编号项目?(而是使用注释掉的选项[resume*]实际上并不能恢复编号!)

注意:我展示了所有交叉引用的内容,因为我需要它们在修复这些问题后仍然有效。(所以我对没有完全最小化示例表示歉意。)

\documentclass{memoir}
\usepackage{amsthm,thmtools}
\usepackage{enumitem}
\usepackage{hyperref}
\hypersetup{colorlinks,linkcolor=red}
\usepackage[nameinlink,noabbrev,capitalize]{cleveref}
\usepackage{crossreftools}

\newcommand{\crefexsname}[1]{\crtrefname{#1}}

\swapnumbers
\declaretheorem[name=theorem,numberwithin=chapter]{theorem}

\declaretheoremstyle[
  headfont= \sffamily\bfseries,
  headpunct={\sffamily\bfseries.},
  postheadspace=0.5em,
  notefont=\mdseries\sffamily,
  bodyfont=\mdseries,
]{exsstyle}
\declaretheorem[
  name=Examples,
  style=exsstyle,
  numberlike=theorem,
  preheadhook=\renewcommand{\qedsymbol}{$\diamond$}\pushQED{\qed},
  postfoothook=\popQED
  ]
{examples}
\counterwithin{examples}{chapter}

% To continue Examples environment:
\declaretheoremstyle[
  headfont= \sffamily\bfseries,
  headpunct={},
  postheadspace=0.5em,
  notefont=\mdseries\sffamily,
  bodyfont=\mdseries,
]{exscontstyle}
\declaretheorem[
  style=exscontstyle,
  name=\protect\continuation\space Examples\hspace{-1.5pt}, %\hspace kludge!
  unnumbered,
  preheadhook=\renewcommand{\qedsymbol}{$\diamond$}\pushQED{\qed},
  postfoothook=\popQED
]{exscont}
% From egreg's https://tex.stackexchange.com/a/430720/13492:
\newcommand{\continuation}{??}
\newenvironment{continueexamples}[1]
 {\renewcommand{\continuation}{\ref*{#1}}\exscont{\sffamily(\crefexsname{#1}), continued.}}
 {\endexscont}

% To resume enumerate after continuation:
\newcounter{savenum}
\newcommand{\savenum}[1]{\setcounter{savenum}{\value{#1}}}
\newcommand{\backnum}[1]{\setcounter{#1}{\value{savenum}}}

\crefname{continuedexamples}{Examples}{Examples}

\crefname{enumi}{}{} % do not use ``Item''

% Cross-referencing enumerated items within Examples:
\newcommand{\crefex}[2]{\hyperref[#2]{\namecref{#1}~\labelcref*{#1}~(\ref*{#2})}}
\newcommand\crefrangeex[3]{\cref{#1}~\crefrange{#2}{#3}}
\crefrangeformat{enumi}{\textup{(}#3#1#4\textup{)}--\textup{(}#5#2#6\textup{)}}

\begin{document}

\mainmatter
\chapter{A chapter}

\begin{examples}[some examples]\label{exmpls}
    \begin{enumerate}
        \item\label{exs:first} A first example.
        \savenum{enumi}
    \end{enumerate}
\end{examples}

\begin{continueexamples}{exmpls}
    \begin{enumerate}%[resume*]
        \backnum{enumi}
        \item\label{exs:second} Another example\qedhere
    \end{enumerate}
\end{continueexamples}

See \cref{exmpls}. 

In particular see \crefex{exmpls}{exs:first} and  \crefex{exmpls}{exs:second}.
In other words, see \crefrangeex{exmpls}{exs:first}{exs:second}.

\end{document}

继续示例环境

有关的: https://tex.stackexchange.com/a/430720/13492https://tex.stackexchange.com/a/125140/13492

答案1

要继续一个定理,您可以使用continuesthmtools 的键。它将前一个定理的标签作为值。可以通过重新定义命令来自定义显示的文本\thmcontinues,但为了在 MWE 中获取格式,我定义了一个mycontinues稍微滥用该headpunct键的新键。这解决了问题 1 和 2。请注意,问题 1 是由于您在定理开头后添加了文本。这与您编写的相同

\begin{theorem} some text
\begin{enumerate}

对于问题 3,请注意 enumitem 文档中提到密钥时说resume

这是在本地完成的。如果您想要全局恢复,请参阅下一节系列。

因此,为了退出定理环境创建的组,您必须手动设置series=<name>then 调用resume*=<name>

这是包含这些更改的示例。

\documentclass{memoir}
\usepackage{amsthm,thmtools}
\usepackage{enumitem}
\usepackage{hyperref}
\hypersetup{colorlinks,linkcolor=red}
\usepackage[nameinlink,noabbrev,capitalize]{cleveref}
\usepackage{crossreftools}

\makeatletter
\newif\ifthmtoolsiscontinuing
\thmt@define@thmuse@key{mycontinues}{%
  \thmt@suspendcounter{\thmt@envname}{\thmt@trivialref{#1}{??}}%
  \thmtoolsiscontinuingtrue
}
\makeatother

\newcommand{\crefexsname}[1]{\crtrefname{#1}}

\swapnumbers
\declaretheorem[name=theorem,numberwithin=chapter]{theorem}

\declaretheoremstyle[
  headfont= \sffamily\bfseries,
  headpunct={%
    \ifthmtoolsiscontinuing
      \mdseries,\ continued.
      \else
      .
      \fi
    },
  postheadspace=0.5em,
  notefont=\mdseries\sffamily,
  bodyfont=\mdseries,
]{exsstyle}
   
\declaretheorem[
  name=Examples,
  style=exsstyle,
  numberlike=theorem,
  qed=$\diamond$ % easier than adding to hooks
  ]
{examples}
\counterwithin{examples}{chapter}

\crefname{enumi}{}{} % do not use ``Item''

% Cross-referencing enumerated items within Examples:
\newcommand{\crefex}[2]{\hyperref[#2]{\namecref{#1}~\labelcref*{#1}~(\ref*{#2})}}
\newcommand\crefrangeex[3]{\cref{#1}~\crefrange{#2}{#3}}
\crefrangeformat{enumi}{\textup{(}#3#1#4\textup{)}--\textup{(}#5#2#6\textup{)}}

\begin{document}

\mainmatter
\chapter{A chapter}

\begin{examples}[some examples]\label{exmpls}
    \begin{enumerate}[series=myenum]
        \item\label{exs:first} A first example.
    \end{enumerate}
\end{examples}

\begin{examples}[mycontinues=exmpls,name=some examples]
    \begin{enumerate}[resume*=myenum]
        \item\label{exs:second} Another example\qedhere
    \end{enumerate}
\end{examples}

See \cref{exmpls}. 

In particular see \crefex{exmpls}{exs:first} and  \crefex{exmpls}{exs:second}.
In other words, see \crefrangeex{exmpls}{exs:first}{exs:second}.

\end{document}

韋姆斯


要获得格式“1.1 示例,继续(一些示例)”,您可以使用键headformat。由于这与 交互不佳\swapnumbers,我定义了一个命令\unswapnumbers,您可以在声明定理之前调用该命令来取消交换效果。

\documentclass{memoir}
\usepackage{amsthm,thmtools}
\usepackage{enumitem}
\usepackage{hyperref}
\hypersetup{colorlinks,linkcolor=red}
\usepackage[nameinlink,noabbrev,capitalize]{cleveref}
\usepackage{crossreftools}

\makeatletter
\newcommand\unswapnumbers{\def\thm@swap{N}}
\newif\ifthmtoolsiscontinuing
\thmt@define@thmuse@key{mycontinues}{%
  \thmt@suspendcounter{\thmt@envname}{\thmt@trivialref{#1}{??}}%
  \thmtoolsiscontinuingtrue
}
\makeatother

\newcommand{\crefexsname}[1]{\crtrefname{#1}}

\swapnumbers
\declaretheorem[numberwithin=chapter]{theorem}

\unswapnumbers

\declaretheoremstyle[
  headfont= \sffamily\bfseries,
  headpunct={\sffamily\bfseries.},
  postheadspace=0.5em,
  notefont=\mdseries\sffamily,
  bodyfont=\mdseries,
  headformat={%
    \NUMBER\ \NAME%
    \ifthmtoolsiscontinuing
      \mdseries,\ continued%
    \fi
    \NOTE%
    }
]{exsstyle}
   
\declaretheorem[
  name=Examples,
  style=exsstyle,
  numberlike=theorem,
  qed=$\diamond$ % easier than adding to hooks
  ]
{examples}
\counterwithin{examples}{chapter}

\crefname{enumi}{}{} % do not use ``Item''

% Cross-referencing enumerated items within Examples:
\newcommand{\crefex}[2]{\hyperref[#2]{\namecref{#1}~\labelcref*{#1}~(\ref*{#2})}}
\newcommand\crefrangeex[3]{\cref{#1}~\crefrange{#2}{#3}}
\crefrangeformat{enumi}{\textup{(}#3#1#4\textup{)}--\textup{(}#5#2#6\textup{)}}

\begin{document}
\mainmatter
\chapter{A chapter}

\begin{examples}[some examples]\label{exmpls}
    \begin{enumerate}[series=myenum]
        \item\label{exs:first} A first example.
    \end{enumerate}
\end{examples}

\begin{examples}[mycontinues=exmpls,name=some examples]
    \begin{enumerate}[resume*=myenum]
        \item\label{exs:second} Another example\qedhere
    \end{enumerate}
\end{examples}

See \cref{exmpls}. 

In particular see \crefex{exmpls}{exs:first} and  \crefex{exmpls}{exs:second}.
In other words, see \crefrangeex{exmpls}{exs:first}{exs:second}.

\begin{theorem}
Some theorem text
\end{theorem}

\end{document}

相关内容