15

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 Answers3

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
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}

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.

Leo Liu
  • 77,365