32

Is there an easy way to put a box around a theorem in LaTeX? For example to state an important theorem.

I tried using page 20 of the ntheorem documentation (http://ctan.mackichan.com/macros/latex/contrib/ntheorem/ntheorem.pdf), but I do not know how to use the package.

  • ntheorem uses pstricks to shade theorem. So you have to compile via latex-ps-pdf or xelatex. -- Maybe the package framed is helpful. – Marco Daniel Nov 26 '11 at 23:43
32

You can use \newmdtheoremenv from the mdframed package:

\documentclass{article}
\usepackage{mdframed}
\usepackage{lipsum}

\newmdtheoremenv{theo}{Theorem}

\begin{document}

\begin{theo}
\lipsum*[1]
\end{theo}

\end{document}

enter image description here

If you only want to frame some theorems, then you can define a new environment using the mdframed environment and some previously defined theorem-like environment:

\documentclass{article}
\usepackage{mdframed}
\usepackage{lipsum}

\newtheorem{theo}{Theorem}
\newenvironment{ftheo}
  {\begin{mdframed}\begin{theo}}
  {\end{theo}\end{mdframed}}

\begin{document}

\begin{ftheo}
\lipsum*[1]
\end{ftheo}

\begin{theo}
\lipsum*[1]
\end{theo}

\end{document}
| improve this answer | |
  • Thank you for the effort.For some reason I don't get the whole box: I miss the bottom and left line. – Nadori Nov 27 '11 at 0:05
  • @Nadori are you sure it's not only a viewer issue? – Gonzalo Medina Nov 27 '11 at 0:11
  • 1
    @Nadori: No there are no problems ;-) – Marco Daniel Nov 27 '11 at 0:26
  • 5
    @Nadori: I noticed that you've received some good answers to your other questions, but you haven't accepted any of them. Please consider marking those answers that you consider to be the best as ‘Accepted’ by clicking on the tickmark below their vote count. This shows which answer helped you most, and it assigns reputation points to the author of the answer (and to you!). – Gonzalo Medina Nov 27 '11 at 0:36
  • 1
    how can i get rid of the enumeration? – Martin Erhardt Apr 27 at 23:53
27

I don't know if the tcolorbox package was available at the time that the question was asked, but here's a small example taken directly from the documentation:

screenshot

% arara: pdflatex
\documentclass{article}

\usepackage{tcolorbox}
\tcbuselibrary{theorems}

\newtcbtheorem[number within=section]{mytheo}{My Theorem}%
{colback=green!5,colframe=green!35!black,fonttitle=\bfseries}{th}

\begin{document}
\begin{mytheo}{This is my title}{theoexample}
  This is the text of the theorem. The counter is automatically assigned and,
  in this example, prefixed with the section number. This theorem is numbered with
  \ref{th:theoexample} and is given on page \pageref{th:theoexample}.
\end{mytheo}

\end{document}
| improve this answer | |
  • 1
    Beautiful! How could you get rid of the numbering? – Crparedes Aug 26 at 8:39
9

Here's a minimum working example (MWE) of how one can use the ntheorem and framed packages to draw a rectangular frame around a theorem environment:

\documentclass{article}
\usepackage{framed} % or, "mdframed"
\usepackage[framed]{ntheorem}
\newframedtheorem{frm-thm}{Theorem}
\begin{document}
\begin{frm-thm}[Pythagoras]
Let $a$, $b$, and $c$ denote the lengths of the sides of a \emph{right 
triangle}, i.e., of a triangle with one angle equal to $90^\circ$. 
Without loss of generality assume that $a\le b<c$. Then
\[ a^2+b^2=c^2. \]
\end{frm-thm}
\end{document}

enter image description here

Check the user guides of the framed and mdframed packages for available options for setting the style of the frame.

| improve this answer | |
5

Here's an example of how you can put some colour into your Theorems using ntheorem combined with PSTricks.

screenshot

\documentclass{article}

\usepackage{pstricks}
\usepackage{pst-grad}
\usepackage{framed}
\usepackage[framed]{ntheorem} 
\usepackage{lipsum}

% framed theorem, red background
\theoremstyle{plain}
\theoremsymbol{}
\theoremseparator{}
\def\theoremframecommand{%
      \psshadowbox[fillstyle=solid,fillcolor=red,linecolor=black]}
\newshadedtheorem{mytheorem}{Special Theorem}

% framed theorem, gradient shading
\theoremstyle{plain}
\theoremsymbol{}
\theoremseparator{}
\def\theoremframecommand{%
      \psshadowbox[fillstyle=gradient,gradbegin=red,gradend=yellow,linecolor=black]}
\newshadedtheorem{myfancytheorem}{Sunset special theorem}

\begin{document}

\begin{mytheorem}
\lipsum[1] 
\end{mytheorem}

\begin{myfancytheorem}
 \lipsum[1]
\end{myfancytheorem}

\end{document}

Either run the above code with

latex myfile.tex
dvips myfile.dvi
ps2pdf myfile.ps

or

xelatex myfile.tex

If you want to run it with pdflatex then add the option pdf to the pstricks load

\usepackage[pdf]{pstricks}

and compile with

pdflatex -shell-escape myfile.tex
| improve this answer | |
1

If you are using thmtools, it should be noted that it can render boxed theorems per se. Example:

\documentclass{report}
\usepackage{thmtools}
\usepackage{lipsum}

\declaretheorem[
  shaded={rulecolor=black, rulewidth=1pt, bgcolor=magenta},
  name=Theorem,
]{thmboxed}

\begin{document}

\begin{thmboxed}
\lipsum[1]
\end{thmboxed}

\end{document}

renders as

this

| improve this answer | |
  • how do you suppress the theorem 1 in the title? – fdzsfhaS Mar 16 at 21:53
  • @DavidWarrenKatz what are you trying to achieve? Just a colored box with floating text inside? While it's possible to misuse thmtools for that by e.g. setting headformat and headpunct to \@empty in the custom theorem style, a better solution would be using boxes, e.g. a \coloredbox around a \minipage. – hoefling Mar 16 at 22:25
0

I'd like to use a box around definitions and theorems, but leaving the header outside of it like:

Theorem 3.15: Sufficient conditions for the existance of...
|---------------------------------------------------------------------------------------------------------|
|     Let      .....                                                                                               |
|                 .....                                                                                              |
|                 .....                                                                                              |
|      Then  ......                                                                                             |
|                 ......                                                                                             |
|                                                                                                                    |
|________________________________________________________________|

It's kinda like I have to put the box INSIDE the theorem body, leaving eventually some space for the title and author...

| improve this answer | |
  • 1
    Welcome to tex.sx. This is really a new question, so please post it separately. You can refer to this question as related, saying why yours is different. – barbara beeton Oct 26 at 13:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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