[Tex/LaTex] Different format for fonttitle and counter in tcolorbox

tcolorbox

I am wondering how can one format the counter and the title differently within tcolorbox. By using fonttitle=\small\bfseries, the results is a bold counter and bold name of the definition e.g.

Definition 2.1: Contraction

However, I would like to accomplish

Definition 2.1: Contraction

Currently I am using the following code

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

Best Answer

I agree that it is a useful feature to format the descriptive text with different font and color. I adopted the helpful answers of Gonzalo Medina and egreg and integrated some modification into the develpment code of tcolorbox. Is is part of version 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

EDIT: The options are applied to your example like this:

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

enter image description here

And here is the documentation of the new options:

enter image description here enter image description here

Related Question