使用 amsthm 创建分为小节的定理列表

使用 amsthm 创建分为小节的定理列表

我想修改listoftheorems命令,以便在每章末尾列出上一章中的定理或定义,并将它们按章节划分(它应该看起来像目录,带有加粗的章节标题,然后在下面列出定理/定义)。我使用的是 amsthm,我希望它看起来有点像ToC 类似定义列表(使用定理环境)(除了用章节代替之外,我希望它在每章末尾生成)。

我当前的设置是,

\documentclass[12pt]{book}

\setcounter{secnumdepth}{5}
\setcounter{tocdepth}{5}

\usepackage{etoolbox}
\usepackage{amsthm,thmtools}

% defining theorem environment
\declaretheorem[
numberwithin = section,
]{theorem}

\declaretheorem[
sibling=theorem,
]{definition}

\begin{document}

\chapter{TEST}

\section{First Section}

\begin{theorem}
This shouldn't be included in the list of theorems from chapter two
\end{theorem}

\chapter{Test}

\section{test}

\begin{definition}[test definition 1]
Test definition
\end{definition}


\begin{theorem}
Best theorem
\end{theorem}

\section{The next section}

\begin{theorem}
Test 2
\end{theorem}

\begin{theorem}
Test 3
\end{theorem}

Now here I want to add a list of the theorems from the last two sections.

\end{document}

我尝试修改listoftheorems命令并根据我的需要调整其他线程的解决方案,但没有成功。任何帮助都非常感谢!

答案1

你可以这样做埃托克

\documentclass[12pt]{book}

\setcounter{secnumdepth}{5}
\setcounter{tocdepth}{5}

\usepackage{etoolbox}
\usepackage{amsthm,thmtools}

% defining theorem environment
\declaretheorem[
numberwithin = section,
]{theorem}

\declaretheorem[
sibling=theorem,
]{definition}

\usepackage{etoc}
\etocsetlevel{theorem}{6}

\AtEndEnvironment{theorem}{%
  \etoctoccontentsline{theorem}{\protect\numberline{\thetheorem}}%
}%

\makeatletter
\newcommand{\mylocallistoftheorems}[1]{%
  \begingroup
% per lazyness we are going to use the default chapter style for rendering
% sections, but the space for the number is then too short
% use tocloft's commands for easier customization
  \patchcmd{\l@chapter}{1.5em}{2em}{}{}%
  \patchcmd{\l@section}{1.5em}{2em}{}{}%
% make regular subection invisible
  \etocsetlevel{subsection}{6}%
% pretend theorem in TOC is like subsection
  \etocsetlevel{theorem}{2}% subsection
% make section (the top level local to chapter) be rendered in TOC like
% a chapter. Needs etoc 1.08k [2017/09/28] for \etocsavedchaptertocline
% else we can do manually saving \l@chapter before usage
  \etocsetstyle{section}
    {}
    {}
    {\etocsavedchaptertocline{\numberline{\etocnumber}\etocname}{\etocpage}}
    {}%
  \etocsetstyle{theorem}
    {}
    {}
% this will be rendered like a non-numbered section, but we could have used
% \numberline here also
    {\etocsavedsectiontocline{Theorem \etocnumber}{\etocpage}}
    {}%
% not deeper than theorem (= subsection)
% top level is anyhow section, as we are local to a chapter
  \etocsetnexttocdepth{theorem}%
% avoid the global book style which does a \clearpage
  \etocarticlestyle
% self-explanatory
  \renewcommand{\contentsname}{List of theorems of this chapter, per sections}%
% goes in pair with \invisiblelocaltableofcontents\label{foobar}
% right after \chapter command
  \tableofcontents\ref{#1}%
  \endgroup
}

\makeatother

\usepackage{hyperref}


\begin{document}

\tableofcontents

\chapter{TEST}

\section{First Section}

\begin{theorem}
This shouldn't be included in the list of theorems from chapter two
\end{theorem}

\chapter{Test}
\invisiblelocaltableofcontents\label{tocchap2}

\section{test}

\begin{definition}[test definition 1]
Test definition
\end{definition}


\begin{theorem}
Best theorem
\end{theorem}

\section{The next section}

\begin{theorem}
Test 2
\end{theorem}

\begin{theorem}
Test 3
\end{theorem}

Now here I want to add a list of the theorems from the last two sections.

\mylocallistoftheorems{tocchap2}

\end{document}

我添加了 hyperref 以便更清晰地演示。

在此处输入图片描述

可以使用\etoclink来获取包含单词的定理的超链接Theorem

相关内容