Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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?

share|improve this question
2  
The ntheorem manual has examples that describe this. google: ntheorem.pdf –  cmhughes Aug 3 '11 at 18:41

3 Answers 3

up vote 7 down vote accepted

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}
share|improve this answer
    
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 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}

enter image description here

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

share|improve this answer

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}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.