按章节划分的定理列表

按章节划分的定理列表

我正在尝试按章节划分定理列表,类似于这里。我正在使用该thmtools软件包,并且已经接近让它工作了。我使用了我发布的链接中的以下代码:

\documentclass[a4paper]{book}
\usepackage{amsthm,thmtools}
\usepackage{xcolor}
\usepackage{framed}
\colorlet{shadecolor}{lightgray!25}

\newtheorem{thm}{Theorem}[chapter]

\newtheoremstyle{definitionsty}{3pt}{3pt}{\slshape}{}{\bfseries}{.}{.5em}{}
\theoremstyle{definitionsty}
\newtheorem{tdefn}{Definition}[chapter]
\newenvironment{defn}
  {\begin{shaded}\begin{tdefn}}
  {\end{tdefn}\end{shaded}}

\usepackage{etoolbox}
\makeatletter
\patchcmd\thmtlo@chaptervspacehack
  {\addtocontents{loe}{\protect\addvspace{10\p@}}}
  {\addtocontents{loe}{\protect\thmlopatch@endchapter\protect\thmlopatch@chapter{\thechapter}}}
  {}{}
\AtEndDocument{\addtocontents{loe}{\protect\thmlopatch@endchapter}}
\long\def\thmlopatch@chapter#1#2\thmlopatch@endchapter{%
  \setbox\z@=\vbox{#2}%
  \ifdim\ht\z@>\z@
    \hbox{\bfseries\chaptername\ #1}\nobreak
    #2
    \addvspace{10\p@}
  \fi
}
\def\thmlopatch@endchapter{}

\makeatother
\renewcommand{\thmtformatoptarg}[1]{ -- #1}
\renewcommand{\listtheoremname}{List of definitions}


\begin{document}

\frontmatter
\listoftheorems[ignoreall,show={tdefn}]

\mainmatter
\chapter{X}

\begin{defn}[My hilarious definition]
bla bla
\end{defn}

\chapter{Y}

\begin{thm}
b
\end{thm}

\chapter{Z}

\begin{defn}[My hilarious definition 2]
bla bla
\end{defn}

\begin{thm}
a
\end{thm}

\end{document}

在此处输入图片描述

此解决方案的唯一“问题”是我想要完整的章节名称,而不仅仅是章节编号。如何修改此代码才能实现此目的?我尝试过自己调整此代码,但无法使其正常工作。

答案1

将章节标题保存为\chaptertitle

\documentclass[a4paper]{book}
\usepackage{amsthm,thmtools}
\usepackage{xcolor}
\usepackage{framed}
\colorlet{shadecolor}{lightgray!25}

\newtheorem{thm}{Theorem}[chapter]

\newtheoremstyle{definitionsty}{3pt}{3pt}{\slshape}{}{\bfseries}{.}{.5em}{}
\theoremstyle{definitionsty}
\newtheorem{tdefn}{Definition}[chapter]
\newenvironment{defn}
  {\begin{shaded}\begin{tdefn}}
  {\end{tdefn}\end{shaded}}

\usepackage{etoolbox}
\newcommand{\chaptertitle}{}% reserve global name
\makeatletter
\patchcmd{\@chapter}{\chaptermark{#1}}{\chaptermark{#1}\xdef\chaptertitle{#1}}{}{}
\patchcmd\thmtlo@chaptervspacehack
  {\addtocontents{loe}{\protect\addvspace{10\p@}}}
  {\addtocontents{loe}{\protect\thmlopatch@endchapter\protect\thmlopatch@chapter{\thechapter~\chaptertitle}}}
  {}{}
\AtEndDocument{\addtocontents{loe}{\protect\thmlopatch@endchapter}}
\long\def\thmlopatch@chapter#1#2\thmlopatch@endchapter{%
  \setbox\z@=\vbox{#2}%
  \ifdim\ht\z@>\z@
    \hbox{\bfseries\chaptername\ #1}\nobreak
    #2
    \addvspace{10\p@}
  \fi
}
\def\thmlopatch@endchapter{}

\makeatother
\renewcommand{\thmtformatoptarg}[1]{ -- #1}
\renewcommand{\listtheoremname}{List of definitions}


\begin{document}

\frontmatter
\listoftheorems[ignoreall,show={tdefn}]

\mainmatter
\chapter{X}

\begin{defn}[My hilarious definition]
bla bla
\end{defn}

\chapter{Y}

\begin{thm}
b
\end{thm}

\chapter{Z}

\begin{defn}[My hilarious definition 2]
bla bla
\end{defn}

\begin{thm}
a
\end{thm}

\end{document}

此版本添加了每个章节,而不仅仅是包含定理的章节。

\documentclass[a4paper]{book}
\usepackage{amsthm,thmtools}
\usepackage{xcolor}
\usepackage{framed}
\colorlet{shadecolor}{lightgray!25}

\newtheorem{thm}{Theorem}[chapter]

\newtheoremstyle{definitionsty}{3pt}{3pt}{\slshape}{}{\bfseries}{.}{.5em}{}
\theoremstyle{definitionsty}
\newtheorem{tdefn}{Definition}[chapter]
\newenvironment{defn}
  {\begin{shaded}\begin{tdefn}}
  {\end{tdefn}\end{shaded}}

\usepackage{etoolbox}
\newcommand{\chaptertitle}{}% reserve global name
\makeatletter
\let\thmtlo@chaptervspacehack\relax
\patchcmd{\@chapter}{\chaptermark{#1}}{\chaptermark{#1}%
  \addtocontents{loe}{\par\noindent\textbf{\@chapapp~\thechapter~#1}}}
  {}{}
\makeatother
\renewcommand{\thmtformatoptarg}[1]{ -- #1}
\renewcommand{\listtheoremname}{List of definitions}


\begin{document}

\frontmatter
\listoftheorems[ignoreall,show={tdefn}]

\mainmatter
\chapter{X}

\begin{defn}[My hilarious definition]
bla bla
\end{defn}

\chapter{Y}

\begin{thm}
b
\end{thm}

\chapter{Z}

\begin{defn}[My hilarious definition 2]
bla bla
\end{defn}

\begin{thm}
a
\end{thm}

\end{document}

相关内容