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.

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
2  
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
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. –  Ulrich Schwarz Feb 26 '11 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 %.) –  Ulrich Schwarz Feb 26 '11 at 9:16

4 Answers 4

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:

\documentclass{article}
\usepackage{color,amsmath}
\usepackage{framed}
\makeatletter
\newdimen\errorsize \errorsize=0.2pt
% Frame with a label at top
\newcommand\LabFrame[2]{%
    \fboxrule=\FrameRule
    \fboxsep=-\errorsize
    \textcolor{FrameColor}{%
    \fbox{%
      \vbox{\nobreak
      \advance\FrameSep\errorsize
      \begingroup
        \advance\baselineskip\FrameSep
        \hrule height \baselineskip
        \nobreak
        \vskip-\baselineskip
      \endgroup
      \vskip 0.5\FrameSep
      \hbox{\hskip\FrameSep \strut
        \textcolor{TitleColor}{\textbf{#1}}}%
      \nobreak \nointerlineskip
      \vskip 1.3\FrameSep
      \hbox{\hskip\FrameSep
        {\normalcolor#2}%
        \hskip\FrameSep}%
      \vskip\FrameSep
    }}%
}}
\definecolor{FrameColor}{rgb}{0.25,0.25,1.0}
\definecolor{TitleColor}{rgb}{1.0,1.0,1.0}

\newenvironment{contlabelframe}[2][\Frame@Lab\ (cont.)]{% 
  % Optional continuation label defaults to the first label plus
  \def\Frame@Lab{#2}%
  \def\FrameCommand{\LabFrame{#2}}%
  \def\FirstFrameCommand{\LabFrame{#2}}%
  \def\MidFrameCommand{\LabFrame{#1}}%
  \def\LastFrameCommand{\LabFrame{#1}}%
  \MakeFramed{\advance\hsize-\width \FrameRestore} 
}{\endMakeFramed} 
\newcounter{theorem}
\newenvironment{theorem}[1]{%
  \par
  \refstepcounter{theorem}%
  \begin{contlabelframe}{Theorem \thetheorem:\quad #1}
 \noindent\ignorespaces}
{\end{contlabelframe}} 
\makeatother
\begin{document}
\begin{theorem}{Pythagoras}
This is a theorem
\end{theorem}
\end{document}

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

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)

\listfiles
\documentclass{article}
\usepackage{amsmath,tikz}
\usepackage[framemethod=default,
skipabove=\topskip,
skipbelow=\topskip,
]{mdframed}
\usepackage{lipsum}
\makeatletter

\makeatletter
\newcounter{theo}[section]
\newcommand*\Mytheoremheader[1]{%
  \@afterindentfalse
   {\parindent \z@
         \setlength{\parfillskip}{\z@ plus 1fil}%
         \mdraggedtitle\nobreak%
         \makebox[\linewidth][l]{%
          \hspace*{-1\mdf@innerleftmargin@length}%
          \rlap{\color{white}%
               \hspace*{-1\mdf@middlelinewidth@length}%
               \rule[\mdf@middlelinewidth@length]%
                    {\dimexpr\linewidth+1\mdf@innerleftmargin@length%
                      +\mdf@innerrightmargin@length
                      +2\mdf@middlelinewidth@length\relax}%
                     {\dimexpr\ht\strutbox+.3333em
                        \relax}%
               }%
          \rlap{\color{blue!20}%
                \rule{\dimexpr\linewidth+\mdf@innerleftmargin@length%
                        +\mdf@innerrightmargin@length\relax}%
                     {\mdf@middlelinewidth@length}}%
          \hspace*{-1\mdf@middlelinewidth@length}%
          \tikz[remember picture,baseline]\node[,draw = none, text = black,
                     fill = blue!20,]
                     {\mdf@frametitlefont\strut Theorem~\thetheo#1};\relax%
         }%
    \par\kern.5\baselineskip}%
  \@afterheading}

\newenvironment{theo}[1][]{%
   \let\mdframedtitleenv\Mytheoremheader%
   \stepcounter{theo}%
   \ifstrempty{#1}{\mdfsetup{frametitle={\strut}}}{\mdfsetup{frametitle={:~#1}}}%
   \begin{mdframed}[innertopmargin=0pt,linecolor=blue!20,linewidth=2pt,topline=false,]%
   }{\end{mdframed}}
\makeatother
\begin{document}
\section{First section}
Text
\begin{theo}[Theorem lipsum]
\lipsum[1]
\end{theo}

\begin{theo}
\lipsum[2]
\end{theo}
\end{document}

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 at 7: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:

\documentclass{article}
\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

\makeatletter%
\newcommand{\theoremhang}{% top theorem decoration
  \begingroup%
  \setlength{\unitlength}{.005\linewidth}% \linewidth/200
    \begin{picture}(0,0)(1.5,0)%
      \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
        \color{black!\iB}%
        \put(-3,\iA){\line(0,-1){1}}% Top left hang
        \put(203,\iA){\line(0,-1){1}}% Top right hang
      }%
    \end{picture}%
  \endgroup%
}%
\newcommand{\theoremhung}{% bottom theorem decoration
  \nobreak
  \begingroup%
    \setlength{\unitlength}{.005\linewidth}% \linewidth/200
    \begin{picture}(0,0)(1.5,0)%
      \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
        \color{black!\iB}%
        \put(-3,\iA){\line(0,1){1}}% Bottom left hang
        \put(203,\iA){\line(0,1){1}}% Bottom right hang
      }%
    \end{picture}%
  \endgroup%
}%

\newcounter{theorem}
\renewcommand{\thetheorem}{\arabic{theorem}}
\NewEnviron{theorem}[1][]{%
    \par\noindent\theoremhang\par\nobreak\noindent%\addvspace{-.5ex}
    \refstepcounter{theorem}\postdisplaypenalty=10000 %
    {\sffamily\bfseries\upshape Theorem \thetheorem\@ifnotmtarg{#1}{\ (#1)}}\ \ \itshape\ignorespaces%
    \BODY % Typeset theorem body/content
    \par\addvspace{-1ex}\nobreak\noindent\theoremhung\par\addvspace{.4ex}%
}
\makeatother

\begin{document}

\lipsum[1]

\begin{theorem}[Special theorem]
\lipsum[2]
\end{theorem}

And then there is also

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

\lipsum[3]

\end{document}

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? –  Andres Caicedo Aug 9 '12 at 18:49

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.