tcolorbox:tcolorbox 列表(\tcblistof...)看起来与 LaTex 图形列表(\listoffigures)不同 - 我该如何更改它?

tcolorbox:tcolorbox 列表(\tcblistof...)看起来与 LaTex 图形列表(\listoffigures)不同 - 我该如何更改它?

在此处输入图片描述我如何改变 tcolorboxes 列表的外观(tcolorbox 手册第 5.2 节)?

问题:使用命令 \tcblistof 得出的 tcolorboxes 列表与标准 LaTex 命令 \listoffigures 得出的图形列表看起来不同。

  1. tcolorbox 列表是章节与章节之间没有垂直空间的列表。
  2. 此外,数字和标题之间没有空格。
  3. 如果使用 \quad 命令在数字和标题之间提供空格,则列表的数字将不会垂直对齐。

我希望提供的所有列表具有相同的外观,这意味着,要么更改图形列表的外观,要么更改 tcolorboxes 列表的外观。

您有什么建议/解决方案吗?下面是我用来生成定义列表和图表列表的代码示例。

非常感谢您的帮助!

谢谢!

\documentclass[]{scrbook}

% Creation of dummy text
\usepackage{blindtext}

%  Environments for my definitions and examples
\usepackage[listings,breakable]{tcolorbox}
\tcbuselibrary{breakable}

\newtcolorbox[auto counter,number within=chapter,list inside=definitions]{definitionbox}[2][]{%
    colframe=red,%
    colback=white,%
    sharp corners=all,%
    boxrule=0.5pt,%
    fonttitle=\sffamily\bfseries,%
    title=Definition~\thetcbcounter: #2,#1,%
    list entry= \thetcbcounter: #2,#1}%


% A definition can be provided within the following environment:
%\begin{definitionbox}[breakable]{Title of Definition}
%\end{definitionbox}

\newtcolorbox[auto counter,number within=chapter,list inside=examples]{examplebox}[2][]{%
    colframe=blue,%
    colback=white,%
    sharp corners=all,%
    boxrule=0.5pt,%
    lower separated=true,%
    fonttitle=\sffamily\bfseries,%
    title=Example~\thetcbcounter: #2,#1,
    list entry= \thetcbcounter: \quad #2,#1}%

% An example can be provided within the following environment:
%\begin{examplebox}[breakable]{Title of Example}
%\tcblower
%\end{examplebox}


\begin{document}

\tableofcontents

% Add List of Definitions to the table of contents
\addcontentsline{toc}{chapter}{List of Definitions}
% List of tcolorboxes, see documentation, Section 5.2
\tcblistof[\chapter*]{definitions}{List of Definitions}

% Add List of Examples to the table of contents
\addcontentsline{toc}{chapter}{List of Examples}
\tcblistof[\chapter*]{examples}{List of Examples}

% Add List of Figures to the table of contents
\addcontentsline{toc}{chapter}{List of Figures}
\listoffigures

\chapter{Important Chapter}

\blindtext[1]

\begin{definitionbox}[label={def:derivative}]{Financial Derivative}
    A financial derivative is a financial contract that is settled at a future date $ T>0 $.
\end{definitionbox}

\blindtext[1]

\begin{examplebox}[breakable]{Title of Example}
Testexample.
\tcblower
Test example solution.
\end{examplebox}


\begin{center}
    \begin{figure}
    Testtext 1  for figure environment.
    \caption{Testcaption 1}
    \end{figure}
\end{center}



\chapter{Even More Important Chapter}

\blindtext[1]

\begin{definitionbox}[label={def:spotprice}]{Spot Price}
    The \emph{spot price} $ S_0$ is the price for immediate delivery at $ t=0 $.
    The spot price $ S_t $ is the (market) price of an asset at a point in time $ t $.
    The spot price $ S_T $ is the (market) price of an asset at maturity $ T $.
\end{definitionbox}

\blindtext[1]

\begin{examplebox}[breakable]{Title of Example 2}
    Testexample 2
    \tcblower
    Test example solution 2.
\end{examplebox}


\begin{center}
    \begin{figure}
        Testtext 2  for figure environment.
        \caption{Testcaption 2}
    \end{figure}
\end{center}

\end{document}

答案1

不要手动将 LoF 添加到 ToC。您应该使用类选项listof=totoc

list entry将tcolorboxes 的选项替换为

list text=#2

并添加以下代码

\addtotoclist[float]{definitions}% same vertical gap for chapters 
\NewDocumentCommand{\listofdefinitions}{}{\listoftoc[List of Definitions]{definitions}}
\setuptoc{definitions}{totoc}% ToC entry for the list of definitions

\addtotoclist[float]{examples}% same vertical gap for chapters
\NewDocumentCommand{\listofexamples}{}{\listoftoc[List of Examples]{examples}}
\setuptoc{examples}{totoc}% ToC entry for the list of examples

然后使用\listofdefinitions\listofexamples作为定义列表和示例列表。

例子:

\documentclass[listof=totoc]{scrbook}% option listof=totoc added
\usepackage{scrhack}% added

\usepackage{blindtext}% Creation of dummy text

%  Environments for my definitions and examples
\usepackage[listings,breakable]{tcolorbox}
\tcbuselibrary{breakable}

\newtcolorbox[auto counter,number within=chapter,list inside=definitions]{definitionbox}[2][]{%
  colframe=red,%
  colback=white,%
  sharp corners=all,%
  boxrule=0.5pt,%
  fonttitle=\sffamily\bfseries,%
  title=Definition~\thetcbcounter: #2,
  %#1,% <- removed
  list text=#2,% changed
  #1}%

\newtcolorbox[auto counter,number within=chapter,list inside=examples]{examplebox}[2][]{%
  colframe=blue,%
  colback=white,%
  sharp corners=all,%
  boxrule=0.5pt,%
  lower separated=true,%
  fonttitle=\sffamily\bfseries,%
  title=Example~\thetcbcounter: #2,
  %#1,% <- removed
  list text=#2,% changed
  #1}%

% ---- added:
\addtotoclist[float]{definitions}
\NewDocumentCommand{\listofdefinitions}{}{\listoftoc[List of Definitions]{definitions}}
\setuptoc{definitions}{totoc}

\addtotoclist[float]{examples}
\NewDocumentCommand{\listofexamples}{}{\listoftoc[List of Examples]{examples}}
\setuptoc{examples}{totoc}
%---

\begin{document}

\tableofcontents
\listofdefinitions% <- changed
\listofexamples% <- changed
\listoffigures

\chapter{Important Chapter}
\blindtext
\begin{definitionbox}[label={def:derivative}]{Financial Derivative}
  A financial derivative is a financial contract that is settled at a future date $ T>0 $.
\end{definitionbox}
\blindtext
\begin{examplebox}[breakable]{Title of Example}
Testexample.
\tcblower
Test example solution.
\end{examplebox}
\begin{figure}
  \centering
  Testtext 1  for figure environment.
  \caption{Testcaption 1}
\end{figure}

\chapter{Even More Important Chapter}
\blindtext[1]
\begin{definitionbox}[label={def:spotprice}]{Spot Price}
  The \emph{spot price} $ S_0$ is the price for immediate delivery at $ t=0 $.
  The spot price $ S_t $ is the (market) price of an asset at a point in time $ t $.
  The spot price $ S_T $ is the (market) price of an asset at maturity $ T $.
\end{definitionbox}
\blindtext[1]
\begin{examplebox}[breakable]{Title of Example 2}
  Testexample 2
  \tcblower
  Test example solution 2.
\end{examplebox}
\begin{figure}
  \centering
  Testtext 2 for figure environment.
  \caption{Testcaption 2}
\end{figure}
\begin{figure}
  \centering
  Testtext 3 for figure environment.
  \caption{Testcaption 3}
\end{figure}
\begin{examplebox}[breakable]{Title of Example 3}
  Testexample 3
  \tcblower
  Test example solution 3.
\end{examplebox}
\end{document}

在此处输入图片描述

在此处输入图片描述


如果列表中的章节之间不应该有间隙等,请使用 KOMA-Script 选项listof=nochaptergap

\documentclass[listof=totoc,listof=nochaptergap]{scrbook}% options listof=totoc and listof=nochaptergap added
\usepackage{scrhack}% added

\usepackage{blindtext}% Creation of dummy text

%  Environments for my definitions and examples
\usepackage[listings,breakable]{tcolorbox}
\tcbuselibrary{breakable}

\newtcolorbox[auto counter,number within=chapter,list inside=definitions]{definitionbox}[2][]{%
  colframe=red,%
  colback=white,%
  sharp corners=all,%
  boxrule=0.5pt,%
  fonttitle=\sffamily\bfseries,%
  title=Definition~\thetcbcounter: #2,
  %#1,% <- removed
  list text= #2,% changed
  #1}%

\newtcolorbox[auto counter,number within=chapter,list inside=examples]{examplebox}[2][]{%
  colframe=blue,%
  colback=white,%
  sharp corners=all,%
  boxrule=0.5pt,%
  lower separated=true,%
  fonttitle=\sffamily\bfseries,%
  title=Example~\thetcbcounter: #2,
  %#1,% <- removed
  list text= #2,% changed
  #1}%

% ---- added:
\addtotoclist[float]{definitions}
\NewDocumentCommand{\listofdefinitions}{}{\listoftoc[List of Definitions]{definitions}}
\setuptoc{definitions}{totoc}

\addtotoclist[float]{examples}
\NewDocumentCommand{\listofexamples}{}{\listoftoc[List of Examples]{examples}}
\setuptoc{examples}{totoc}
%---

\begin{document}

\tableofcontents
\listofdefinitions% <- changed
\listofexamples% <- changed
\listoffigures

\chapter{Important Chapter}
\blindtext
\begin{definitionbox}[label={def:derivative}]{Financial Derivative}
  A financial derivative is a financial contract that is settled at a future date $ T>0 $.
\end{definitionbox}
\blindtext
\begin{examplebox}[breakable]{Title of Example}
Testexample.
\tcblower
Test example solution.
\end{examplebox}
\begin{figure}
  \centering
  Testtext 1  for figure environment.
  \caption{Testcaption 1}
\end{figure}

\chapter{Even More Important Chapter}
\blindtext[1]
\begin{definitionbox}[label={def:spotprice}]{Spot Price}
  The \emph{spot price} $ S_0$ is the price for immediate delivery at $ t=0 $.
  The spot price $ S_t $ is the (market) price of an asset at a point in time $ t $.
  The spot price $ S_T $ is the (market) price of an asset at maturity $ T $.
\end{definitionbox}
\blindtext[1]
\begin{examplebox}[breakable]{Title of Example 2}
  Testexample 2
  \tcblower
  Test example solution 2.
\end{examplebox}
\begin{figure}
  \centering
  Testtext 2 for figure environment.
  \caption{Testcaption 2}
\end{figure}
\begin{figure}
  \centering
  Testtext 3 for figure environment.
  \caption{Testcaption 3}
\end{figure}
\begin{examplebox}[breakable]{Title of Example 3}
  Testexample 3
  \tcblower
  Test example solution 3.
\end{examplebox}
\end{document}

在此处输入图片描述

在此处输入图片描述

相关内容