TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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 (I'm using LyX and don't often come in contact with LaTeX code)?

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

share|improve this question
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 '11 at 23:06
Since you want to use LyX I'll only comment, that the thmtools package has features for what you want. – Carsten Thiel Feb 15 '11 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. – Mikael Öhman Feb 15 '11 at 12:12
@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. – Ulrich Schwarz Feb 26 '11 at 9:04
@Mikael: for completeness' sake: \declaretheorem[% preheadhook={\begin{mdframed}[leftline=true,rightline=false,% topline=false,bottomline=false]},% postfoothook=\end{mdframed}% ]{theorem} (with linbreaks after each %.) – Ulrich Schwarz Feb 26 '11 at 9:16

I had a different Question but maybe the answer from Marco is what you are searching for: Different colorcoded theorems

Example Output from my thesis: enter image description here

share|improve this answer

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

share|improve this answer
tried copying this into LyX (in LaTeX preamble) and I get LaTeX error: command \c@theorem already defined. – Amir Rachum Feb 15 '11 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 '11 at 17:08

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

share|improve this answer
A small follow-up: How does one prevent page breaks that would make the bottom "frame" appear alone at the beginning of a page? – Andrés E. Caicedo Aug 9 '12 at 18:49

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]


share|improve this answer
I don't get this output with TeXLive 2014. The output I get is with the title and top line missing as shown here. – Peter Grill Oct 23 '14 at 7:08
Yepp, me to - with miktex 2.9. – lukas.coenig Mar 12 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}} – lukas.coenig Mar 12 at 8:05

Your Answer


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.