0

I'm typing some lecture notes I had with some theorems, propositions, axioms, etc., and I want to modify the style for such environments: add macros, shaded backgrounds, or any simple modification (Change background color of title using declaretheoremstyle).

I've used this solution before: Using mdframed style within \declaretheoremstyle to change title. It uses \declaretheorem to implement such style, but the template I've now been using uses \newtheorem instead. Here's my attempt, which doesn't work as the style I declared does not apply.

\documentclass{article}

\usepackage{amsmath,amsthm}
\usepackage{mathtools,thmtools,framed}
\usepackage{lipsum}

\declaretheoremstyle[
    mdframed={
        backgroundcolor=gray!20, 
            linecolor=gray!30, 
            innertopmargin=6pt,
            innerbottommargin=6pt} 
]{box}

\newtheorem*{definition}{Definition}
\theoremstyle{box} 
\newtheorem{theorem}{Theorem}[section]
\newtheorem{axiom}{Axiom}
\newtheorem{corollary}[theorem]{Corollary}
\newtheorem{lemma}[theorem]{Lemma}
\newtheorem{proposition}[theorem]{Proposition}

\begin{document}

\section{Intro}

\begin{theorem}
\lipsum[2][4]
\end{theorem}

\end{document}

So, my question is how to implement the modified style in the \newtheorem environment. Any other solution or comment is welcome.

2
  • 2
    Welcome! If you like that style, why not use it? It's not clear what you mean by a 'template' but if you mean a preamble which basically loads a bunch of packages for you, you are almost certainly better without it. You haven't mentioned any good reason to use \newtheorem rather than \declaretheorem.
    – cfr
    Commented Nov 2, 2023 at 5:43
  • I suggest to look at tcolorbox instead. With that you just define environments as usual with \newtheorem and “adorn” them later.
    – egreg
    Commented Nov 2, 2023 at 9:44

1 Answer 1

0

I suggest to use tcolorbox instead.

\documentclass{article}

\usepackage{amsmath,amsthm}
\usepackage[many]{tcolorbox}

\usepackage{lipsum}

\newtheorem*{definition}{Definition}
\newtheorem{theorem}{Theorem}[section]
\newtheorem{axiom}{Axiom}
\newtheorem{corollary}[theorem]{Corollary}
\newtheorem{lemma}[theorem]{Lemma}
\newtheorem{proposition}[theorem]{Proposition}

% defina a style to be applied for theorem-like environments
\tcbset{
  manuel-theorems/.style={
    sharp corners,
    skin=tile,
    colback=gray!20,
  },
}

% wrap the desired environments
\ExplSyntaxOn
\clist_map_inline:nn {theorem,axiom,corollary,lemma,proposition}
 {
  \tcolorboxenvironment{#1}{manuel-theorems}
 }
\ExplSyntaxOff

\begin{document}

\section{Intro}

\begin{theorem}
\lipsum[2][4]
\end{theorem}

\begin{proposition}
\lipsum[2][4]
\end{proposition}

\end{document}

enter image description here

I used a mapping over a list rather than a long series of declarations such as

\tcolorboxenvironment{theorem}{manuel-theorems}

for each environment.

1
  • Thank you so much! Great answer, exactly what I was looking for
    – Manuel E
    Commented Nov 2, 2023 at 17:48

You must log in to answer this question.

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