如何为 tcolorbox 设置简短标题

如何为 tcolorbox 设置简短标题

我目前正在尝试使用彩色盒子包(参见本背面文件)我使用下面的代码来设置定理框:

\usepackage{tcolorbox}
\tcbuselibrary{listings,theorems,breakable}
\newtcbtheorem[auto counter,number within=chapter,list inside={th}]{theorem}{Theorem}%
{colback=black!5,colframe=black!25!gray,fonttitle=\bfseries, breakable}{th}

然后我创建一个定理列表:

    \tcblistof[\section*]{th}{List of Theorems}

并使用以下语法向我的文本添加几个定理:

\begin{theorem}{Famous theorem \footnote{Created by Einstein.}}{famous_theorem}
\begin{equation}
    E= m c^2
\end{equation}
\end{theorem}

然而,这会引发几个错误,因为彩色盒子包不知道如何处理定理标题中的脚注。我查看了文档,但我还没有找到一种方法来为不包含脚注的定理创建一个简短的标题。因此,我的问题是,是否可以为 tcolorbox 设置一个简短的标题,就像使用命令为图形设置的那样caption

我已经尝试过

我尝试添加一个带有简短标题的说明,但这似乎不起作用,因为颜色框是浮点数。我还尝试了以下语法:

\begin{theorem}[title={[Short title.]{Long title \footnoote{test}}}]{A famous theorem \footnote{A footnote.}}{famous_theorem}
    \begin{equation}
        E= m c^2
    \end{equation}
\end{theorem}

但这并没有给出正确的标题并且仍然会引发错误。

答案1

自 tcolorbox v5.1.1 (2022/06/24) 起,不再支持(按框或按定理)短标题。因此,我在 tcolorbox 的 repo 中打开了一个功能请求,请参阅TFS/tcolorbox#186

结合我的尝试(参见功能请求)和脚注技巧:

\documentclass{report} % to allow `number within=chapter`
\usepackage{tcolorbox}
\tcbuselibrary{breakable, hooks, theorems,}

\ExplSyntaxOn
% case 2, tcb theorem

% Syntax of theorem envs to be created
%   \begin{<thmname>}[<options>]{<title>}{<label>}
%   \begin{<thmname>}[<options>][<short title>]{<title>}{<label>} <<< new
%   \begin{<thmname>*}{<title>}{<label>}
\NewDocumentCommand \NewTcbTheorem {}
  {
    % "x" stands for xparse (actually latex kernel uses `ltcmd.dtx`)
    \__tcobox_new_tcbtheorem_x:w \NewTColorBox
  }
% and its Declare..., Renew..., and Provide... variants

\NewDocumentCommand \__tcobox_new_tcbtheorem_x:w { m O{} m m +m m }
  {
    #1 [auto~counter,#2] {#3} { +O{} +o +m m }
      {
        #5,
        title      = {\__tcobox_theo_title:nnn{#4}{\thetcbcounter}{##3}},
        IfValueTF  = {##2}
          { % short title is given
            list~entry = {\protect\numberline{\thetcbcounter}##2},
            nameref    = {##2},
          }
          {
            list~entry = {\protect\numberline{\thetcbcounter}##3},
            nameref    = {##3},
          },
        theo@label = {#6}{##4},
        ##1
      }
    #1 [#2,no~counter,list~inside=] {#3*} { +O{} +m }
      {
        #5,
        title = {\__tcobox_theo_title:nnn{#4}{}{##2}},
        ##1
      }
  }
\ExplSyntaxOff

\begin{document}
\tcblistof[\section*]{th}{List of Theorems}

\chapter{}

\NewTcbTheorem[auto counter, number within=chapter, list inside={th}]
  {theorem}
  {Theorem}
  {colback=black!5, colframe=black!25!gray, fonttitle=\bfseries, breakable}
  {th}

% Syntax:
%   \begin{theorem}[options]{title}{label}
%   \begin{theorem}[options][short title]{title}{label} <<< new syntax
%   \begin{theorem*}{title}{label}

Text\footnote{dummy footnote}.

\begin{theorem}{Famous theorem looong title}{famous_theorem}
  \begin{equation}
      E= m c^2
  \end{equation}
\end{theorem}

\begin{theorem}[][Famous theorem short title]{Famous theorem looong title\footnote{Created by Einstein.}}{famous_theorem2}
  Footnote is placed at end of title.
  \begin{equation}
      E= m c^2
  \end{equation}
\end{theorem}

\begin{theorem}[][Famous theorem short title]{Famous theorem looong title\textsuperscript{$a$}}{famous_theorem3}
  Footnote is placed at end of current box.
  \begin{equation}
      E= m c^2
  \end{equation}
  \footnotetext[1]{Created by Einstein.}
\end{theorem}

% option `after app` needs tcb library `hooks`
\begin{theorem}[after pre=\footnotetext{Created by Einstein.}][Famous theorem short title]{Famous theorem looong title\footnotemark}{famous_theorem3}
  Footnote is placed at end of current page.
  \begin{equation}
      E= m c^2
  \end{equation}
\end{theorem}

Text\footnote{another dummy footnote}.
\end{document}

定理列表 定理

相关内容