如果您要返回此问题,请参阅下面的编辑,尽管取得了一些进展,但问题仍未得到解答
我正在为我正在上的一门课程写讲义。我正在尝试为一组定理环境创建一个目录,这些定理环境不是通常的定理环境tcolorbox
。
tcolorbox
在使用定理之前,我有一个烦恼,因为定理要求在由我发表的另一篇文章中定义的每个定理环境的部分{}{}
后面都加上两个,\begin{}
newtcbtheorem
用户能够巧妙地定义外部betternewtcbtheorem
使用 expl3 避免了对选项的需求,现在标题和标签是可选的。
我在序言中提到了五种betternewtcbtheorem
环境:
- 定理
- 定义
- 推论
- 主张
- 引理
有些有标题,但不是全部,有些有标签,但不是全部。有些在章节中的部分,有时在章节中,但不在部分中
目标:我正在尝试使目录列出其所属的每个章节或部分下的每个定理、定义、推论、定义、引理以及页码。如果对象有标题,我想包括其标题;如果没有标题,则只包括定理编号。我还想使目录可点击(最好使用包,hyperref
以便轻松浏览)。
我尝试过在线发布的其他解决方案,但我不明白如何修改它们以使其与这个外部定义一起工作,因为它们是在常规theorem
环境下制作的
一个例子(模仿文章后面的代码)如下:
Lecture 1... Pg#
Theorem 1.1: Test Theorem 1...
Prop 1.1: Test Prop 2...
Section 1... Pg#
Theorem 1.2...
Lemma 1.1: Test Lemma 1...
Definition 1.1: Definition 1...
Lecture 2... Pg#
Theorem 2.1: Test Theorem 3
Corollary 2.1
我给出了以下结构的工作示例:
\documentclass[12pt]{report}
\usepackage[dvipsnames]{xcolor}
\usepackage[parfill]{parskip}
\usepackage[margin=1in]{geometry}
\usepackage{empheq}
\usepackage[most]{tcolorbox}
\usepackage{amsmath , amsthm , amssymb, mathtools}
\usepackage[all]{xy}
\usepackage{titlesec}
\usepackage{hyperref}
\hypersetup{
colorlinks,
linkcolor={blue!80!black},
citecolor={blue!50!black},
urlcolor={blue!80!black}
}
\titleformat{\chapter}[display]
{\normalfont\bfseries\centering}{}{0pt}{\LARGE}
\titlespacing{\chapter}{0pt}{-75pt}{\parskip}
\tcbuselibrary{theorems}
\setcounter{secnumdepth}{0}
%This is where betternewtcbtheorem definition starts
\ExplSyntaxOn
\NewDocumentCommand{\betternewtcbtheorem}{O{}mmmm}
{
\newtcbtheorem[#1]{#2inner}{#3}{#4}{#5}
\NewDocumentEnvironment{#2}{O{}}
{
\keys_set:nn { hushus/tcb } { ##1 }
%Start of where I add to the table of contents
\phantomsection
\addcontentsline{toc}{subsection}{#3: \hspace{0.4em}\l__hushus_tcb_title_tl}
%End of where I add to table of contents
\hushus_tcb_begin:nVV {#2inner} \l__hushus_tcb_title_tl \l__hushus_tcb_label_tl
}
{
\end{#2inner}
}
\cs_if_exist:cF { c@#5} { \newcounter{#5} }
}
\cs_new_protected:Nn \hushus_tcb_begin:nnn
{
\begin{#1}{#2}{#3}
}
\cs_generate_variant:Nn \hushus_tcb_begin:nnn { nVV }
\keys_define:nn { hushus/tcb }
{
title .tl_set:N = \l__hushus_tcb_title_tl,
label .tl_set:N = \l__hushus_tcb_label_tl,
}
\ExplSyntaxOff
%This is where betternewtcbtheorem definition ends.
\betternewtcbtheorem[number within = chapter]{dfn}{Definition}%
{
enhanced,
before title = {\stepcounter{dfn}},
colback=blue!10,
colframe=blue!35!black,
fonttitle=\bfseries,
top=3mm,
attach boxed title to top left={xshift = 5mm, yshift=-1.5mm},
boxed title style = {colback=blue!35!black}
}{dfn}
\betternewtcbtheorem[number within = chapter]{thm}{Theorem}%
{
enhanced,
before title = {\stepcounter{thm}},
colback=green!10,
colframe=green!35!black,
fonttitle=\bfseries,
top=3mm,
attach boxed title to top left={xshift = 5mm, yshift=-1.5mm},
boxed title style = {colback=green!35!black}
}{thm}
\betternewtcbtheorem[number within = chapter]{prop}{Proposition}%
{
enhanced,
before title = {\stepcounter{thm}},
colback=cyan!10,
colframe=cyan!35!black,
fonttitle=\bfseries,
top=3mm,
attach boxed title to top left={xshift = 5mm, yshift=-1.5mm},
boxed title style = {colback=cyan!35!black}
}{prop}
\betternewtcbtheorem[number within = chapter]{lem}{Lemma}%
{
enhanced,
before title = {\stepcounter{thm}},
colback=Dandelion!10,
colframe=Dandelion!35!black,
fonttitle=\bfseries,
top=3mm,
attach boxed title to top left={xshift = 5mm, yshift=-1.5mm},
boxed title style = {colback=Dandelion!35!black}
}{lem}
\betternewtcbtheorem[number within= chapter]% init options
{crl}% name environment
{Corollary}% Title
{enhanced,
before title = {\stepcounter{co}},
colback=red!10,
colframe=red!35!black,
fonttitle=\bfseries,
top=3mm,
attach boxed title to top left={xshift = 5mm, yshift=-1.5mm},
boxed title style = {colback=red!35!black}
}% options
{co}% label prefix
\begin{document}
\tableofcontents
\chapter{Lecture 1}
\begin{thm}[title = Test Theorem 1,label=thm1]
abc
\end{thm}
\begin{prop}[title = Test Prop 2,label=prop1]
abc
\end{prop}
\section{Section 1}
\begin{thm}
abc
\end{thm}
\begin{lem}[title = Test Lemma 1]
abc
\end{lem}
\begin{dfn}[title = Definition 1]
abc
\end{dfn}
\chapter{Lecture 2}
\begin{thm}[title=Test Theorem 3]
\end{thm}
\begin{crl}
abc
\end{crl}
\end{document}
编辑:
正如您所见,通过添加引用环境名称及其可选标题的\newdocumentenvironment
部分,我得到了一些与我想要的工作相似的效果。\addcontentsline
当前的问题是:无法显示环境编号(如定理 1.1),并且如果环境没有标题则不包括冒号(如第二定理)。
答案1
我可以帮你解决部分问题。我对“betternewtcbtheorem-part”一无所知,所以我希望你能自己整合这部分内容。希望这个答案能帮助你进一步寻找最终答案。
\documentclass[12pt]{report}
\usepackage[dvipsnames]{xcolor}
\usepackage[parfill]{parskip}
\usepackage[margin=1in]{geometry}
\usepackage{empheq}
\usepackage[most]{tcolorbox}
\usepackage{amsmath , amsthm , amssymb, mathtools}
\usepackage[all]{xy}
\usepackage{titlesec}
\titleformat{\chapter}[display]
{\normalfont\bfseries\centering}{}{0pt}{\LARGE}
\titlespacing{\chapter}{0pt}{-75pt}{\parskip}
\tcbuselibrary{theorems}
\setcounter{secnumdepth}{0}
% For the preamble theorems:
% \newtcbtheorem [#1 initial options] {#2 environment name}
% {#3 Theorem title name} {#4 options} {ref #5:##3}
% For the theorems inside your document:
% \begin {#2} [##1 extra options] {##2 Title Name} {##3 refname}
% content
% \end{#2}
\makeatletter
\renewcommand{\new@tcbtheorem}[5][]{%
% numbered theorem
\@@newtcolorbox[#1, auto counter, number within=section,
list inside=theoremlist]%
{#2}[3][]{#4, ##1%
title={\tcb@theo@title{#3}{\thetcbcounter}{##2}},
list entry={\protect\numberline{\yourfont#3~\thetcbcounter}##2},
code={\tcb@theo@label{#5}{##3}}}%
% unnumbered theorem*
\@@newtcolorbox[#1, no counter, list inside=theoremlist]%
{#2*}[2][]{#4, ##1,%
title={\tcb@theo@title{#3}{\@empty}{##2}},
list entry={\protect\numberline{\yourfont#3}##2},
}}
\makeatother
% Then place all your theorem environments
\newtcbtheorem[]% init options
{dfn}{Definition}%
{
enhanced,
colback=blue!10,
colframe=blue!35!black,
fonttitle=\bfseries,
top=3mm,
attach boxed title to top left={xshift = 5mm, yshift=-1.5mm},
boxed title style = {colback=blue!35!black}
}{dfn}
\newtcbtheorem[]% init options
{thm}{Theorem}%
{
enhanced,
colback=green!10,
colframe=green!35!black,
fonttitle=\bfseries,
top=3mm,
attach boxed title to top left={xshift = 5mm, yshift=-1.5mm},
boxed title style = {colback=green!35!black}
}{thm}
\newtcbtheorem[]% init options
{prop}{Proposition}%
{
enhanced,
colback=cyan!10,
colframe=cyan!35!black,
fonttitle=\bfseries,
top=3mm,
attach boxed title to top left={xshift = 5mm, yshift=-1.5mm},
boxed title style = {colback=cyan!35!black}
}{prop}
\newtcbtheorem[]% init options
{lem}{Lemma}%
{
enhanced,
colback=Dandelion!10,
colframe=Dandelion!35!black,
fonttitle=\bfseries,
top=3mm,
attach boxed title to top left={xshift = 5mm, yshift=-1.5mm},
boxed title style = {colback=Dandelion!35!black}
}{lem}
\newtcbtheorem[]% init options
{crl}% name environment
{Corollary}% Title
{enhanced,
colback=red!10,
colframe=red!35!black,
fonttitle=\bfseries,
top=3mm,
attach boxed title to top left={xshift = 5mm, yshift=-1.5mm},
boxed title style = {colback=red!35!black}
}% options
{co}% label prefix
% Then define your preferred Theorem ToC settings
\newcommand{\yourfont}{\itshape}% Theorem ToC font
\makeatletter
\renewcommand*\l@tcolorbox{\@dottedtocline{1}{0pt}{100pt}}% indent, numwidth
\makeatother
% Then place the Theorem ToC in the preferred location of your document
\begin{document}
\tableofcontents
% ToC Theorems as section inside your main ToC
\tcblistof[\section*]{theoremlist}{List of Theorems}
\chapter{Lecture 1}
\begin{thm}[]{Test Theorem 1}{thm1}% title and ref label
abc
\end{thm}
Referring the Theorem number by \ref{thm:thm1}.
\begin{prop}[]{Test Prop 2}{prop1}
abc
\end{prop}
\section{Section 1}
\begin{thm}[]{}{}
abc
\end{thm}
\begin{lem}[]{Test Lemma 1}{}
abc
\end{lem}
\begin{dfn}[]{Definition 1}{}
abc
\end{dfn}
\chapter{Lecture 2}
\begin{thm}[]{Test Theorem 3}{}
\end{thm}
\begin{crl}[]{}{}
abc
\end{crl}
\end{document}