3

In the following MWE, how can we change theorem label to \textcolor{blue}{Theorem} \textcolor{magenta}{1} ?


\documentclass{article}
\usepackage{xcolor}
\usepackage{tcolorbox}
\tcbuselibrary{theorems}
\newtcbtheorem{theorem}{Theorem}{fonttitle=\color{blue}}{}
\begin{document}
    \begin{theorem}{}{}
        How can we change color of theorem label to \textcolor{blue}{Theorem} \textcolor{magenta}{1} ?
    \end{theorem}
\end{document}
4

The colour of the theorem title is defined by the coltitle option, however, since both title and theorem number are set automatically one has to change the number format of the underlying tcbcounter.

This can be done with the init option number freestyle={...}

Since this option is expanded, the expansion of the code at definition of the theorem must be prevented with \noexpand.

For more information about the numbering of boxes with tcolorbox see section 5 of the manual, please!

Of course the title background has to be changed as well (use colbacktitle=...) otherwise the title is hard to read!

\documentclass{article}
\usepackage{xcolor}
\usepackage{tcolorbox}
\tcbuselibrary{theorems}
\newtcbtheorem[number freestyle={\noexpand\textcolor{magenta}{\noexpand\arabic{\tcbcounter}}}]{theorem}{Theorem}{fonttitle=\color{blue},coltitle=blue}{}


\begin{document}
    \begin{theorem}{A nice theorem}{}
        How can we change color of theorem label to \textcolor{blue}{Theorem} \textcolor{magenta}{1} ?
    \end{theorem}
\end{document}

enter image description here

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.