这是我的 MWE:
\documentclass{report}
\usepackage[usenames,dvipsnames,pdftex]{xcolor}
\usepackage{amsmath,amsfonts,mathtools,amsthm,amssymb}
\usepackage{mdframed}
\usepackage{varwidth}
\usepackage{thmtools}
\usepackage[most,many,breakable]{tcolorbox}
\usepackage{color}
\tcbuselibrary{theorems,skins,hooks}
\mdfsetup{skipabove=1em,skipbelow=0em}
\definecolor{example}{HTML}{00A6E4}
\makeatletter
\def\zz{\edef\zzz{\pdfliteral{\current@color}}}
\makeatother
\declaretheoremstyle[
headfont=\bfseries\zz\color{example}, bodyfont=\normalfont, headpunct=
]{thmexamplebox}
\declaretheorem[numberwithin=chapter, style=thmexamplebox, name=EXAMPLE]{example}
\renewcommand{\theexample}{\arabic{example}}
\begin{document}
\begin{example}
hi
\end{example}
\end{document}
这将创建以下 pdf:
如何向环境标题添加如下所示的背景颜色?
另外,他们使用什么类型的字体?
如果可能的话,我想像上面一样使用declaretheoremstyle
和declaretheorem
,因为我的所有其他定理也在使用它。
答案1
找到答案了!!
\documentclass{report}
\usepackage[usenames,dvipsnames,pdftex]{xcolor}
\usepackage{amsmath,amsfonts,mathtools,amsthm,amssymb}
\usepackage{mdframed}
\usepackage{varwidth}
\usepackage{thmtools}
\usepackage[most,many,breakable]{tcolorbox}
\usepackage{color}
\tcbuselibrary{theorems,skins,hooks}
\mdfsetup{skipabove=1em,skipbelow=0em}
\definecolor{example}{HTML}{00A6E4}
\definecolor{examplebg}{HTML}{CAE4F0}
\makeatletter
\def\zz{\edef\zzz{\pdfliteral{\current@color}}}
\makeatother
\declaretheoremstyle[
headfont=\sffamily\bfseries\zz\color{example}\colorbox{examplebg}{EXAMPLE \arabic{example}},
headformat=\NOTE,
notefont=\bfseries,
bodyfont=\normalfont,
notefont=\zzz\bfseries,
notebraces={~ },
headpunct=,
]{thmexamplebox}
\declaretheorem[numberwithin=chapter, style=thmexamplebox, name=] {example}
\renewcommand{\theexample}{\arabic{example}}
\begin{document}
\begin{example}[Finding Maclaurin series by multiplication and division]
Find the first three nonzero terms in the Maclaurin series for (a) $e^{x}$
and (b) $\tan(x)$.
\end{example}
\end{document}
这将创建以下 pdf: