tcolorbox 中字体标题和计数器的格式不同

tcolorbox 中字体标题和计数器的格式不同

我想知道如何在 tcolorbox 中以不同的方式格式化计数器和标题。通过使用fonttitle=\small\bfseries,结果是粗体计数器和粗体定义名称,例如

定义 2.1:收缩

然而,我想实现

定义2.1:收缩

目前我正在使用以下代码

    \documentclass [10pt, twoside, openright, a5paper, showtrims]{memoir}     
    \newtcbtheorem[auto counter,number within=chapter]{myDefinition}{Definition}{
            unbreakable,
            enhanced,
            arc=0pt,
            outer arc=0pt,
            coltitle=black,
            fonttitle=\small\bfseries,
            fontupper=\noindent,
            left=7pt,
            lefttitle=7pt,
            boxsep=2pt,
            right=7pt,}{def}
    \begin{document}
    \chapter{Intro}
    \chapter{Basic}
    \begin{myDefinition}{Contraction}{co-simulation}
    some text
    \end{myDefinition}
\begin{end}

答案1

我同意用不同的字体和颜色格式化描述性文本是一项有用的功能。我采纳了 Gonzalo Medina 和 egreg 的有用答案,并将一些修改集成到 的开发代码中tcolorbox。它是 版本的一部分3.00 (2014/05/08)

%-- modification usable for tcolorbox
%-- version 2.70 (2014/02/06) to version 2.80 (2014/03/31)
%-- integrated into version 3.00 (2014/05/08) and above
\makeatletter
\def\tcb@theo@desc@form@std#1{\tcb@desc@col\kvtcb@desc@font\kvtcb@desc@delim@left#1\kvtcb@desc@delim@right}

\def\tcb@theo@title#1#2#3{%
  \ifdefempty{#2}{\setbox\z@=\hbox{#1}}{\setbox\z@=\tcb@theo@form{#1}{#2}}%
  \def\temp@a{#3}%
  \ifx\temp@a\@empty\relax%
    \unhbox\z@\kvtcb@terminatorsign%
  \else%
    \setbox\z@=\hbox{\unhbox\z@\kvtcb@separatorsign\ }%
    \hangindent\wd\z@%
    \hangafter=1%
    \mbox{\unhbox\z@}{\tcb@theo@desc@form{#3}}\kvtcb@terminatorsign%
  \fi%
}

\tcbset{
  description color/.code={\def\temp@a{#1}\ifx\temp@a\@empty\relax%
    \def\tcb@desc@col{}\else\def\tcb@desc@col{\color{#1}}\fi},
  description color/.default=,
  description font/.store in=\kvtcb@desc@font,
  description font/.default=,
  description formatter/.code={\let\tcb@theo@desc@form=#1},
  description formatter/.default={\tcb@theo@desc@form@std},
  description formatter,description color,description font
}
\makeatother
%-- end of modification

编辑:这些选项应用于您的示例,如下所示:

\documentclass [10pt, twoside, openright, a5paper, showtrims]{memoir}
\usepackage{tcolorbox}
\tcbuselibrary{theorems,skins,breakable}

%-- insert modification from above if using tcolorbox
%-- version 2.70 (2014/02/06) to version 2.80 (2014/03/31)
%-- NOT needed for version 3.00 (2014/05/08) and above

\newtcbtheorem[auto counter,number within=chapter]{myDefinition}{Definition}{
  unbreakable,
  enhanced,
  arc=0pt,
  outer arc=0pt,
  coltitle=white,
  fonttitle=\small\bfseries,
  description font=\normalfont,
  left=7pt,
  boxsep=2pt,
  right=7pt,
}{def}

\begin{document}
\chapter{Intro}
\chapter{Basic}
\begin{myDefinition}{Contraction}{co-simulation}
some text
\end{myDefinition}
\end{document}

在此处输入图片描述

以下是新选项的文档:

在此处输入图片描述 在此处输入图片描述

答案2

在当前版本中,无法为注释提供单独的字体格式,但我想这是一个有用的功能,可以包含在软件包中。我会让软件包作者知道这个要求,并可能在新版本中将其包含在内。

同时,这里有一个重新定义的选项,\tcb@theo@title包括\notefont格式化注释字体;您可以\notefont\normalfont我的示例中更改为适合您需要的任何内容。

\documentclass [10pt, twoside, openright, a5paper, showtrims]{memoir}
\usepackage[many]{tcolorbox}

\makeatletter
\newcommand\notefont{\normalfont}
\def\tcb@theo@title#1#2#3{%
  \ifdefempty{#2}{\setbox\z@=\hbox{#1}}{\setbox\z@=\tcb@theo@form{#1}{#2}}%
  \def\temp@a{#3}%
  \ifx\temp@a\@empty\relax%
    \unhbox\z@\kvtcb@terminatorsign%
  \else%
    \setbox\z@=\hbox{\unhbox\z@\kvtcb@separatorsign\ }%
    \hangindent\wd\z@%
    \hangafter=1%
    \mbox{\unhbox\z@}{\notefont\kvtcb@desc@delim@left#3\kvtcb@desc@delim@right\kvtcb@terminatorsign}%
  \fi%
}
\makeatother

\newtcbtheorem[auto counter,number within=chapter]{myDefinition}{Definition}{
            unbreakable,
            enhanced,
            arc=0pt,
            outer arc=0pt,
            coltitle=black,
            fonttitle=\small\bfseries,
            fontupper=\noindent,
            left=7pt,
            lefttitle=7pt,
            boxsep=2pt,
            right=7pt,
}{def}

\begin{document}
    \chapter{Intro}
    \chapter{Basic}
    \begin{myDefinition}{Contraction}{co-simulation}
    some text
    \end{myDefinition}
\end{document}

在此处输入图片描述

答案3

我建议修改 Gonzalo 的答案,定义一个新键来设置用于描述的字体:

\documentclass [10pt, twoside, openright, a5paper, showtrims]{memoir}
\usepackage{tcolorbox}
\tcbuselibrary{theorems,skins,breakable}

\makeatletter
\tcbset{
  fontdescription/.store in=\kvtcb@desc@font,
  fontdescription=,% set default 
}

%%% the definition copied from tcbtheorems.code.tex, with one addition
\def\tcb@theo@title#1#2#3{%
  \ifdefempty{#2}{\setbox\z@=\hbox{#1}}{\setbox\z@=\tcb@theo@form{#1}{#2}}%
  \def\temp@a{#3}%
  \ifx\temp@a\@empty\relax
    \unhbox\z@\kvtcb@terminatorsign
  \else
    \setbox\z@=\hbox{\unhbox\z@\kvtcb@separatorsign\ }%
    \hangindent\wd\z@
    \hangafter=\@ne
    \mbox{\unhbox\z@}\kvtcb@desc@delim@left
    \kvtcb@desc@font %%% <------------------------- added
    #3\kvtcb@desc@delim@right\kvtcb@terminatorsign
  \fi
}
\makeatother

\newtcbtheorem[auto counter,number within=chapter]{myDefinition}{Definition}{
  unbreakable,
  enhanced,
  arc=0pt,
  outer arc=0pt,
  coltitle=black,
  fonttitle=\small\bfseries\color{white}, % white for seeing the words
  fontdescription=\normalfont,
  fontupper=\noindent,
  left=7pt,
  lefttitle=7pt,
  boxsep=2pt,
  right=7pt,
}{def}

\begin{document}
\chapter{Intro}
\chapter{Basic}
\begin{myDefinition}{Contraction}{co-simulation}
some text
\end{myDefinition}
\end{document}

在此处输入图片描述

相关内容