4

I am using tcolorbox package for my custom theorem like environment.

\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}

and this is what I am getting after compiling it.screenshot But I want to change the color of the number counter too ('Algorithm 1.1') to myblue. I tried using coltitle=myblue but it is changing color of the whole title. I want 'Example Algorithm' to stay in default black color.

Any help is appreciated.

1 Answer 1

4

Use coltitle=myblue and description color=black!85.

(Also remove the explicit \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}

MWE output

3
  • Thanks for your help. But unfortunately it is not working, I am getting the same result after compiling it.
    – Alan
    May 31 at 12:15
  • @Lily I added an MWE for debugging (just yours with the two options changed). You are getting a different output from it?
    – schtandard
    May 31 at 13:27
  • It is working now, I think it was a problem with my compiler. Thanks a lot.
    – Alan
    May 31 at 14:16

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .