我正在使用 tcolorbox 包来构建类似自定义定理的环境。
\documentclass{article}
\usepackage{xcolor}
\usepackage{tcolorbox}
\tcbuselibrary{theorems,skins,hooks}
\definecolor{myblue}{RGB}{0, 61, 116}
\newcounter{algorithmcounter}
\newtcbtheorem[number within=section]{algorithminner}{\textcolor{myblue}{Algorithm}}
{%
enhanced,
colback=blue!10,
frame hidden,
boxrule=0pt,
borderline west={2pt}{0pt}{myblue},
sharp corners,
detach title,
before upper=\tcbtitle\par\smallskip,
coltitle=black!85,
fonttitle=\bfseries\sffamily,
description font=\mdseries,
separator sign none,
segmentation style={solid, black!85},
}{th}
\newenvironment{algorithm}[1]
{\stepcounter{algorithmcounter}\begin{algorithminner}{#1}{algorithm-\arabic{section}-\arabic{algorithmcounter}}}
{\end{algorithminner}}
\begin{document}
\section{Example Section}
\begin{algorithm}{Example Algorithm}
This is an example algorithm.
\end{algorithm}
\end{document}
这是我编译后得到的结果。
但我想将数字计数器的颜色(“算法 1.1”)也更改为 myblue。我尝试使用,coltitle=myblue
但它改变了整个标题的颜色。我希望“示例算法”保持默认的黑色。
任何帮助都将受到赞赏。
答案1
使用coltitle=myblue
和description color=black!85
。
(也删除明确的\textcolor
。)
\documentclass{article}
\usepackage{xcolor}
\usepackage{tcolorbox}
\tcbuselibrary{theorems,skins,hooks}
\definecolor{myblue}{RGB}{0, 61, 116}
\newcounter{algorithmcounter}
\newtcbtheorem[number within=section]{algorithminner}{Algorithm}
{%
enhanced,
colback=blue!10,
frame hidden,
boxrule=0pt,
borderline west={2pt}{0pt}{myblue},
sharp corners,
detach title,
before upper=\tcbtitle\par\smallskip,
coltitle=myblue,
description color=black!85,
fonttitle=\bfseries\sffamily,
description font=\mdseries,
separator sign none,
segmentation style={solid, black!85},
}{th}
\newenvironment{algorithm}[1]
{\stepcounter{algorithmcounter}\begin{algorithminner}{#1}{algorithm-\arabic{section}-\arabic{algorithmcounter}}}
{\end{algorithminner}}
\begin{document}
\section{Example Section}
\begin{algorithm}{Example Algorithm}
This is an example algorithm.
\end{algorithm}
\end{document}