# Highlight environment by setting a gray background color

The title explains everything. I have a theorem with ntheorem and want to highlight it with a gray background color. What would be the easiest way to achieve this?

-
The ntheorem manual has examples that describe this. google: ntheorem.pdf –  cmhughes Aug 3 '11 at 18:41

Just use mdframed package. Here is an example from the document with a little modification:

\documentclass{article}
\usepackage{xcolor}
\usepackage{mdframed}
\newtheorem{mdtheorem}{Theorem}
\newenvironment{theorem}%
{\begin{mdframed}[backgroundcolor=lightgray]\begin{mdtheorem}}%
{\end{mdtheorem}\end{mdframed}}

\begin{document}

\begin{theorem}
test
\end{theorem}

\end{document}

-
Seems that TeX Live lacks exactly this package. Any other solution? –  Christian Ivicevic Aug 3 '11 at 17:51
I'm sure that TeX Live 2011 have this package. But your TeX dist may be too old. –  Leo Liu Aug 3 '11 at 17:55
For now, I trust you that it works - furthermore i have changed the highlighting box to \theorem(pre|post)work{(\bigskip\hrule|\hrule\bigskip)} and it's good enough. Hope you understand my notation :D –  Christian Ivicevic Aug 3 '11 at 17:58
You can either install the mdframed package manually, or update your TeX Live distribution. According to a quick compilation of @Leo's code on ScribTeX - which runs pdftex from TeX Live 2009 - it compiles without problem. –  Werner Aug 3 '11 at 17:59
This solution works great even with TeX Live 2010. –  Peter Grill Aug 3 '11 at 18:09

Here's a solution that uses ntheorems built-in shaded theorems; note that this version requires pstricks, and hence you can not use pdflatex. It breaks across pages just fine.

\documentclass{article}
\usepackage[standard,framed]{ntheorem}
\usepackage{framed}
\usepackage{pstricks}
\usepackage{lipsum}
\usepackage{xcolor}
\definecolor{silver}{rgb}{0.95,0.95,0.95}

\theoremstyle{break}
\theoremsymbol{}
\theoremseparator{}
\def\theoremframecommand{%

\begin{document}

\lipsum[1]

\end{document}

-

Here's another solution without mdframed package. It is NOT as good as the mdframed solution. The whole theorem environment is put in a box, thus it cannot be break between pages. You may need to put it in a float.

\documentclass{article}
\usepackage{xcolor}
\newsavebox\thmbox
\newtheorem{mytheorem}{Theorem}
\newenvironment{theorem}%
{\begin{lrbox}{\thmbox}%
\begin{minipage}{\dimexpr\linewidth-2\fboxsep}
\begin{mytheorem}}%
{\end{mytheorem}%
\end{minipage}%
\end{lrbox}%
\begin{trivlist}
\item[]\colorbox{lightgray}{\usebox\thmbox}
\end{trivlist}}

\begin{document}

\begin{theorem}
test
\end{theorem}

\end{document}


Note: Don't use it if you can access mdframed package. I made it CW and I don't need any score from this.

-