2

I am starting with a classical theorem environment from amsthm, it has the numbering I want. What I would like is to color the background of the name of the theorem. I have tried to do a color box in the definition itself, but I only get to color the name, unfortunately without the numbering. Basically, my question is: how to get the numbering to be colored as well?

I am aware of the package thmtools but I am only trying to color the background of the name and numbering, not the whole theorem.

MWE:

\documentclass{article}

\usepackage{amsmath,amsthm}

\usepackage{xcolor}
\usepackage{colortbl}

\definecolor{1}{RGB}{255,200,255}
\newtheorem{prop1}{\colorbox{1}{Proposition}}

\begin{document}

\begin{prop1}
For any information provision policy $A$,
\[
\rho^*_A = 1.
\]
\end{prop1}

\end{document}

Solely <code>Proposition' is colored, whereas I would like the numbering</code>1.' to be colored as well.

Cryme
  • 761

1 Answers1

2

You could define your own theorem style:

\documentclass{article}

\usepackage{amsmath,amsthm}

\usepackage{xcolor}
\usepackage{colortbl}

\definecolor{1}{RGB}{255,200,255}
\newtheoremstyle{colth}% 
{}{}% 
{\itshape}{}% 
{}{}% 
{ }% 
{\colorbox{1}{\textbf{\thmname{#1}\thmnumber{ #2}}\thmnote{ (#3)}.}}
\newtheorem{prop}{Proposition}
\theoremstyle{colth}
\newtheorem{prop1}[prop]{Proposition}

\begin{document}
\begin{prop}
An ordinary Proposition
\end{prop}

\begin{prop1}
For any information provision policy $A$,
\[
\rho^*_A = 1.
\]
\end{prop1}

\begin{prop}[With a note]
For any information provision policy $A$,
\[
\rho^*_A = 1.
\]
\end{prop}

\begin{prop1}[With a note]
For any information provision policy $A$,
\[
\rho^*_A = 1.
\]
\end{prop1}

\end{document}

enter image description here

CarLaTeX
  • 62,716
  • That's exactly what I was looking for, it works like a charm. I would just add that I used \bf to make the text bold-faced, to be more coherent with the other theorem style. – Cryme Nov 30 '18 at 15:35
  • 2
    @OlivierMassicot \bf is deprecated, use \bfseries instead, see here: https://tex.stackexchange.com/questions/41681/correct-way-to-bold-italicize-text and see my edit. – CarLaTeX Nov 30 '18 at 15:55
  • I see, thank you! However I noticed that the numbering counts the number of prop1 theorems, and obviously not the number of propositions. Is there a way where I can have a prop1 and prop2 defined, such that the numbering is the sum of the numberings, i.e. so that it goes Proposition 1., Proposition 2., etc. irrespective of the colors?

    Or is there a way to pass the color as an argument, something like \begin{colorprop}[red] ... \end{colorprop}?

    – Cryme Nov 30 '18 at 17:16
  • Yes, I think I should have framed my initial question differently. I am basically using a color code to refer to propositions in a visual way. I need a color only once, thus I need many propositions with a different style each. No worry, thank you! – Cryme Nov 30 '18 at 17:43
  • 1
    @OlivierMassicot See if my renewed answer fits your needs. – CarLaTeX Nov 30 '18 at 18:44
  • Yes it does! I ticked the green check mark. – Cryme Nov 30 '18 at 19:00
  • 1
    @OlivierMassicot Thank you for accepting my answer. – CarLaTeX Nov 30 '18 at 19:01