I have tried the following code,

\documentclass{article}
\usepackage{amsthm,amssymb,xcolor}
\theoremstyle{plain}
\newtheorem{thm}{Theorem}
\begin{document}
\begin{color}{blue}{\begin{thm}\begin{color}{red}{The     theorem.}\end{thm}}\end{color}
\end{document}

But it isn't working. So, my questions are the following,

  1. How can I solve the problem? As example, what will be the code for the following,

The heading will be colored blue and the body of the theorem will be colored, red.

  1. What will be the codes of the same if the documentclass be book or memoir?
up vote 5 down vote accepted

The simplest way is with the thmtools interface.

\documentclass{article}
\usepackage{amsthm,thmtools,xcolor}

\declaretheoremstyle[
  headfont=\color{blue}\normalfont\bfseries,
  bodyfont=\color{red}\normalfont\itshape,
]{colored}

\declaretheorem[
  style=colored,
  name=Theorem,
]{thm}

\begin{document}

\begin{thm}
The theorem.
\end{thm}

\end{document}

enter image description here

  • What about other documentclasses? – user 170039 Dec 17 '15 at 13:53
  • @user170039 I see no problem in using the same code. – egreg Dec 17 '15 at 13:53

You can achieve your result by declaring a newtheoremstyle as detailed on page 9 of the amsthm documentation:

% declare a new theorem style
\newtheoremstyle{mystyle}%
{3pt}% Space above
{3pt}% Space below 
{\itshape\color{red}}% Body font
{}% Indent amount
{\bfseries\color{blue}}% Theorem head font
{.}% Punctuation after theorem head
{.5em}% Space after theorem head
{}% Theorem head spec (can be left empty, meaning ‘normal’)

You can then use it as:

% use the new theorem style
\theoremstyle{mystyle}
\newtheorem{thm}{Theorem}

Here's a complete example, the output is as in egreg's answer.

% arara: pdflatex
 \documentclass{book}
\usepackage{amsthm,xcolor}

% declare a new theorem style
\newtheoremstyle{mystyle}%
{3pt}% Space above
{3pt}% Space below 
{\itshape\color{red}}% Body font
{}% Indent amount
{\bfseries\color{blue}}% Theorem head font
{.}% Punctuation after theorem head
{.5em}% Space after theorem head 
{}% Theorem head spec (can be left empty, meaning ‘normal’)

% use the new theorem style
\theoremstyle{mystyle}
\newtheorem{thm}{Theorem}

\begin{document}
\begin{thm}
The theorem.
\end{thm}
\end{document}
  • the color{red} might have the side effect off increasing the vertical space separating environments. Sadly, I cannot reproduce this issue now. – pluton Oct 18 '16 at 21:29

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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