Math & ScienceHow to make Theorems with colored boxes?

Information and discussion about LaTeX's math and science related features (e.g. formulas, graphs).
Post Reply
M.A
Posts: 58
Joined: Sun Nov 30, 2008 10:42 am

How to make Theorems with colored boxes?

Post by M.A »

Hello,

How to make theorems show inside a box filled with a certain color ?
I need it also to split over two pages if the theorem was at the end of a page.

Regards,

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

gmedina
Posts: 2313
Joined: Wed Jul 11, 2007 11:45 pm

How to make Theorems with colored boxes?

Post by gmedina »

Hi,

you could try the shaded environment from the framed package. A little example:

Code: Select all

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

\colorlet{shadecolor}{orange!15}

\newtheorem{theorem}{Theorem}

\newenvironment{theo}
  {\begin{shaded}\begin{theorem}}
  {\end{theorem}\end{shaded}}

\begin{document}

\begin{theo}
Some important theorem.
\end{theo}

\end{document}
1,1,2,3,5,8,13,21,34,55,89,144,233,...
User avatar
shadgrind
Posts: 140
Joined: Thu Jul 16, 2009 12:39 am

How to make Theorems with colored boxes?

Post by shadgrind »

You could also try the shadethm package:

Code: Select all

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

\newshadetheorem{thm}{Theorem}
\definecolor{shadethmcolor}{HTML}{EDF8FF}
\definecolor{shaderulecolor}{HTML}{45CFFF}
\setlength{\shadeboxrule}{.4pt}

\begin{document}

\begin{thm}
Some important theorem.
\end{thm}

\end{document}
System: TeX Live 2012, Fedora 18 x86_64, GNU Emacs 24.2
M.A
Posts: 58
Joined: Sun Nov 30, 2008 10:42 am

Re: How to make Theorems with colored boxes?

Post by M.A »

Thanks very much!
It worked with me.
but how to make shading with two colors (the shading changes gradually from the first color to the second color vertically or horizontally)?
User avatar
shadgrind
Posts: 140
Joined: Thu Jul 16, 2009 12:39 am

How to make Theorems with colored boxes?

Post by shadgrind »

If you want a gradient background, then you need to use something different. One way is to use TikZ. Here's an example using both horizontal and vertical gradients:

Code: Select all

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

\newtheorem{thm}{Theorem}
\newcommand{\statetheoremhoriz}[2][\textwidth]{
 \par\noindent\tikzstyle{mybox} = [draw=blue,left color=cyan!50,
  right color=cyan!5,thick,rectangle,inner sep=6pt]
 \begin{tikzpicture}
  \node [mybox] (box){%
   \begin{minipage}{#1}{#2}\end{minipage}
  };
 \end{tikzpicture}
}
\newcommand{\statetheoremvert}[2][\textwidth]{
 \par\noindent\tikzstyle{mybox} = [draw=blue,top color=cyan!50,
  bottom color=cyan!5,thick,rectangle,inner sep=6pt]
 \begin{tikzpicture}
  \node [mybox] (box){%
   \begin{minipage}{#1}{#2}\end{minipage}
  };
 \end{tikzpicture}
}
\newcommand{\statetheoremsolid}[2][\textwidth]{
 \par\noindent\tikzstyle{mybox} = [draw=blue,fill=cyan!50,
  thick,rectangle,inner sep=6pt]
 \begin{tikzpicture}
  \node [mybox] (box){%
   \begin{minipage}{#1}{#2}\end{minipage}
  };
 \end{tikzpicture}
}

\begin{document}

\statetheoremhoriz{
\begin{thm}
Some important theorem. It is very important. So important that
it is in a shaded box with a horizontal gradient.
\end{thm}
}

\statetheoremvert{
\begin{thm}
Another important theorem. It is very important. So important
that it is in a shaded box with a vertical gradient.
\end{thm}
}

\statetheoremsolid{
\begin{thm}
Not such an important theorem. That is why it is in a box with
solid shading.
\end{thm}
}

\end{document}
M.A
Posts: 58
Joined: Sun Nov 30, 2008 10:42 am

Re: How to make Theorems with colored boxes?

Post by M.A »

Thank you very much!
Regards,
Post Reply