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?
3 Answers
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? Aug 3, 2011 at 17:51
-
I'm sure that TeX Live 2011 have this package. But your TeX dist may be too old.– Leo LiuAug 3, 2011 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 Aug 3, 2011 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, 2011 at 17:59 -
Here's a solution that uses ntheorem
s 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{%
\psshadowbox[fillstyle=solid,fillcolor=silver,linecolor=black]}
\newshadedtheorem{myshadedtheorem}{Definition}
\begin{document}
\begin{myshadedtheorem}
\lipsum[1]
\end{myshadedtheorem}
\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.
ntheorem
manual has examples that describe this. google: ntheorem.pdf