I'm writing an article with some theorems and I would like to use special formatting for the theorems - my idea is putting a grey line in the side of the theorem. Can you please show me how to do this?

Also, if you have other ideas for nice formatting for theorems, etc., I would like to hear it.

  • Could you show an example of the sort of thing you want? The packages amsthm or ntheorem might achieve what you want.
    – Seamus
    Feb 14, 2011 at 23:06
  • 2
    Since you want to use LyX I'll only comment, that the thmtools package has features for what you want. Feb 15, 2011 at 9:59
  • I went ahead and tried to create a custom theorem style using thmtools to fit the design Amir wants. I was not successful. I couldn't for the life of me figure out how to use the theoremdefiner. Feb 15, 2011 at 12:12
  • 1
    @Mikael: you're not supposed to tap into theoremdefiner. Without having given a deeper look, giving preheadhook and postfoothook keys should be sufficient, similar to the way it's done for the shaded key. Feb 26, 2011 at 9:04
  • 1
    @Mikael: for completeness' sake: \declaretheorem[% preheadhook={\begin{mdframed}[leftline=true,rightline=false,% topline=false,bottomline=false]},% postfoothook=\end{mdframed}% ]{theorem} (with linbreaks after each %.) Feb 26, 2011 at 9:16

5 Answers 5


I had a different question but maybe the answer from Marco Daniel is what you are searching for: Different colorcoded theorems. He proposed using the package mdframed.

Example Output from my thesis: Result similar to Marco Daniel's answer


I recently requested some help with theorem decorations in Theorem decorations that stay with theorem environment. I wanted something the discerns from regular text (to make the theorem stand out), but not too much. Additionally, the environment should be easily breakable across pages without causing problems (with orphaned/widowed decorations) or being visually "broken" (like a truncated frame). The result, after some modifications, yields this:

\usepackage{xcolor}% http://ctan.org/pkg/xcolor
\usepackage{ifmtarg}% http://ctan.org/pkg/ifmtarg
\usepackage{xifthen}% http://ctan.org/pkg/xifthen
\usepackage{environ}% http://ctan.org/pkg/environ
\usepackage{multido}% http://ctan.org/pkg/multido
\usepackage{lipsum}% http://ctan.org/pkg/lipsum

\newcommand{\theoremhang}{% top theorem decoration
  \setlength{\unitlength}{.005\linewidth}% \linewidth/200
      \linethickness{0.45pt} \color{black!50}%
      \put(-3,2){\line(1,0){206}}% Top line
      \multido{\iA=2+-1,\iB=50+-10}{5}{% Top hangs
        \put(-3,\iA){\line(0,-1){1}}% Top left hang
        \put(203,\iA){\line(0,-1){1}}% Top right hang
\newcommand{\theoremhung}{% bottom theorem decoration
    \setlength{\unitlength}{.005\linewidth}% \linewidth/200
      \linethickness{0.45pt} \color{black!50}%
      \put(-3,0){\line(1,0){206}}% Bottom line
      \multido{\iA=0+1,\iB=50+-10}{5}{% Bottom hangs
        \put(-3,\iA){\line(0,1){1}}% Bottom left hang
        \put(203,\iA){\line(0,1){1}}% Bottom right hang

    \refstepcounter{theorem}\postdisplaypenalty=10000 %
    {\sffamily\bfseries\upshape Theorem \thetheorem\@ifnotmtarg{#1}{\ (#1)}}\ \ \itshape\ignorespaces%
    \BODY % Typeset theorem body/content



\begin{theorem}[Special theorem]

And then there is also

\begin{theorem}[Short theorem]
This is just a short theorem description.



Theorem decorations

  • 1
    A small follow-up: How does one prevent page breaks that would make the bottom "frame" appear alone at the beginning of a page? Aug 9, 2012 at 18:49

Not exactly what you want but this is an example by Donald Arseneau that uses framed package:

\newdimen\errorsize \errorsize=0.2pt
% Frame with a label at top
        \hrule height \baselineskip
      \vskip 0.5\FrameSep
      \hbox{\hskip\FrameSep \strut
      \nobreak \nointerlineskip
      \vskip 1.3\FrameSep

\newenvironment{contlabelframe}[2][\Frame@Lab\ (cont.)]{% 
  % Optional continuation label defaults to the first label plus
  \MakeFramed{\advance\hsize-\width \FrameRestore} 
  \begin{contlabelframe}{Theorem \thetheorem:\quad #1}
This is a theorem

And This is what you get:

enter image description here

  • tried copying this into LyX (in LaTeX preamble) and I get LaTeX error: command \c@theorem already defined. Feb 15, 2011 at 16:47
  • Do you use amsthm or any other theorem thing package, if you do, then firstly you need to delete or comment \newcounter{theorem}.
    – IRAN
    Feb 15, 2011 at 17:08

Another possibility to decorate theorems is shown in the example above. The example is also shown in the new version 1.0 of mdframed (uploaded today)


   {\parindent \z@
         \setlength{\parfillskip}{\z@ plus 1fil}%
          \tikz[remember picture,baseline]\node[,draw = none, text = black,
                     fill = blue!20,]
                     {\mdf@frametitlefont\strut Theorem~\thetheo#1};\relax%

\section{First section}
\begin{theo}[Theorem lipsum]


  • 1
    I don't get this output with TeXLive 2014. The output I get is with the title and top line missing as shown here. Oct 23, 2014 at 7:08
  • Yepp, me to - with miktex 2.9. Mar 12, 2016 at 6:48
  • This worked for me: \newcounter{theo}[chapter] \newenvironment{theo}[1]{% \stepcounter{theo}% \ifstrempty{#1}% {\mdfsetup{% frametitle={% \tikz[baseline=(current bounding box.east),outer sep=0pt] \node[anchor=east,rectangle,fill=blue!20] {\strut Theorem~\thetheo};}} }% {\mdfsetup{% frametitle={% \tikz[baseline=(current bounding box.east),outer sep=0pt] \node[anchor=east,rectangle,fill=blue!20] {\strut Theorem~\thetheo:~#1};}}% }% \mdfsetup{innertopmargin=10pt,linecolor=blue!20,% linewidth=2pt,topline=true, frametitleaboveskip=-12.5pt, } \begin{mdframed}[]\relax% }{\end{mdframed}} Mar 12, 2016 at 8:05

Later in 2011 Thomas F. Sturm published a nice package called tcolorbox for creating such special effects like the ones you desire. Like this you do not need to create such a big overhead in the preamble as the other answers' examples.

Here I give you a MWE but for more details please look at the package manual:


\newtcbtheorem[number within=section]{mytheo}{My Theorem}%


\begin{mytheo}{This is the theorem title}{label_of_the_theorem}
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:label_of_the_theorem} and is given on page \pageref{th:label_of_the_theorem}.

The theorem enumerator adds the number of the section as indicated in the preamble.


Output after compilation. Boxed theorem with title

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.