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?
Asked
Active
Viewed 1.7k times
15
Christian Ivicevic
- 1,205
3 Answers
12
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}
Leo Liu
- 77,365
-
Seems that TeX Live lacks exactly this package. Any other solution? – Christian Ivicevic Aug 03 '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 03 '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 03 '11 at 17:58 -
You can either install the
mdframedpackage 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 03 '11 at 17:59 -
-
@Christian: I understand your temporary solution well, although it is not very well. :) – Leo Liu Aug 03 '11 at 18:12
-
3
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{%
\psshadowbox[fillstyle=solid,fillcolor=silver,linecolor=black]}
\newshadedtheorem{myshadedtheorem}{Definition}
\begin{document}
\begin{myshadedtheorem}
\lipsum[1]
\end{myshadedtheorem}
\end{document}
cmhughes
- 100,947
2
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.
Leo Liu
- 77,365
ntheoremmanual has examples that describe this. google: ntheorem.pdf – cmhughes Aug 03 '11 at 18:41