8

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}
  • 1
    Welcome to the site! It would be great if you could turn your snippet into a complete minimal working example (MWE), as it really helps members of the community to reproduce the problem you're having :) – cmhughes Apr 10 '14 at 16:49
  • Sorry, but what's the meaning of writing black on black? – egreg Apr 10 '14 at 18:08
4

In the present version there's no way to give a separate font formatting for the note, but I guess this is a useful feature that could be included in the package. I'll let the package author know about this requirement and possibly in a new version it will be included.

In the meantime, here's an option redefining \tcb@theo@title to include \notefont to format the annotation font; you can change \notefont from \normalfont in my example to whatever suits your needs.

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

enter image description here

  • @Stefan You're welcome! Don't forget that you can accept answers that you consider solved your problems by clicking the checkmark to their left, In case of doubt, please see How do you accept an answer?. – Gonzalo Medina Apr 10 '14 at 18:31
  • @GonzaloMedina I've seen your comment and I integrated the new features for the next tcolorbox. I also added an answer with all details :-) – Thomas F. Sturm Apr 11 '14 at 11:42
4

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

3

I propose a modification of Gonzalo's answer that defines a new key for setting the font used for the description:

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

enter image description here

  • I took over the suggestions of Gonzalo Medina and of yourself for the next tcolorbox release. I've added an answer with details. – Thomas F. Sturm Apr 11 '14 at 11:46
  • @ThomasF.Sturm That was I hoped. Thanks for your work on this awesome package. – egreg Apr 11 '14 at 12:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.