0

I would like to change the theorem environment so that the title and name are coloured. What can I do? Have checked ways to do this (e.g. with \newtheoremstyle) but have not worked well yet. I do not want to use theorom packages such as amsthm, but stick with basic built-in theorem structure.

\documentclass[12pt]{article}
\usepackage[b5paper,body={13cm,18cm}]{geometry}
\usepackage{xcolor}  

\begin{document}

\begin{theorem}[Continuous Function]
  Let \(f\) be a function whose derivative exists in every point,
  then \(f\) is a continuous function.
\end{theorem}

\end{document}

I would have other environments using \newtheorem that I would want the same colouring scheme as would happen with \begin{theorem} ... \end{theorem}.

11
  • 1
    Can you add a minimal working example so we can see which of the theorem packages you are using? Sep 7, 2022 at 10:48
  • 3
    Does this answer your question? Changing the color of theorem headings
    – campa
    Sep 7, 2022 at 11:18
  • I could not get that one to work for me.
    – Veak
    Sep 7, 2022 at 11:21
  • That example does not even compile. You still need to define theorem. This should be diable using thmtools (haven't tested it) or directly via amsthm and defining custom theorem styles.
    – daleif
    Sep 7, 2022 at 11:49
  • 1
    I'm voting to leave open because the OP asks for a solution without amsthm, which makes it a different question.
    – Marijn
    Sep 7, 2022 at 13:27

2 Answers 2

1

In https://tex.stackexchange.com/a/17555/4427 you find the default values for theorem styles. You just need to tailor the last argument to your needs.

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

\newtheoremstyle{colorplain}
  {\topsep}   % ABOVESPACE
  {\topsep}   % BELOWSPACE
  {\itshape}  % BODYFONT
  {0pt}       % INDENT (empty value is the same as 0pt)
  {\bfseries} % HEADFONT
  {.}         % HEADPUNCT
  {5pt plus 1pt minus 1pt} % HEADSPACE
  {%
   \thmnumber{\textcolor{red!75}{#1}}%
   \ % space
   \thmname{\textcolor{green!60!red}{#2}}%
   \thmnote{ \textcolor{blue!80!green}{#3}}%
  }

\theoremstyle{colorplain}
\newtheorem{theorem}{Theorem}

\begin{document}

\begin{theorem}
This has no theorem note.
\end{theorem}

\begin{theorem}[Note]
This has a theorem note.
\end{theorem}

\end{document}

enter image description here

But this is definitely ugly. I believe you just want one color for the whole heading.

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

\newtheoremstyle{colorplain}
  {\topsep}   % ABOVESPACE
  {\topsep}   % BELOWSPACE
  {\itshape}  % BODYFONT
  {0pt}       % INDENT (empty value is the same as 0pt)
  {\color{blue!80!green}\bfseries} % HEADFONT
  {.}         % HEADPUNCT
  {5pt plus 1pt minus 1pt} % HEADSPACE
  {}

\theoremstyle{colorplain}
\newtheorem{theorem}{Theorem}

\begin{document}

\begin{theorem}
This has no theorem note.
\end{theorem}

\begin{theorem}[Note]
This has a theorem note.
\end{theorem}

\end{document}

enter image description here

0

Albeit using both the amsthm and thmtools environments, something like this?

(I also corrected the run-on sentence and corrected the preposition "in" to be "at.")

\documentclass[12pt]{article}
\usepackage[b5paper,body={13cm,18cm}]{geometry}
\usepackage{xcolor}  
\usepackage{amsmath,amsthm}
\usepackage{thmtools}

\declaretheoremstyle[
  headfont={\color{red}\bfseries},
  notefont={\color{blue}},
]{thmstyle}
%
\declaretheorem[name=Theorem, style=thmstyle]{theorem}

\begin{document}

\begin{theorem}[Continuous Function]
  If \(f\) is a function whose derivative exists at every point,
  then \(f\) is a continuous function.
\end{theorem}

\end{document}

Color theorem head and note

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .