Fork Me on GitHub

mdframed

auto-split frame environment for LaTeX

Download this project as a .zip file Download this project as a tar.gz file

Work in progress.

Quick introduction

Welcome! This homepage provides a quick introduction to mdframed, a LaTeX package for auto-split frame environments. For further details please refer to the documentation. The original goal of the mdframed package is the possibility of "drawing frames around theorems which can be splitted on several pages."

What is mdframed?

mdframed is a LaTeX package for drawing frames around a given material. Through the manipulation of frames by a simplified <key>=<value> syntax, mdframed is able to provide several features and also support several packages.

mdframed is already shipped with MikTeX and TeX Live and it's also available in the Comprehensive TeX Archive Network - CTAN. You can easily update the package through your update manager. The development branch is available here at GitHub.

How does mdframed draw the frames?

The package provides three different options for drawing a frame:

  1. mdframed can use default LaTeX commands like \\rule or \\hrule, so no extra package is loaded.
  2. The package can rely on TikZ, giving you more options to manipulate the frames.
  3. mdframed can also rely on PSTricks. You will have more options to manipulate the frames.

Basic usage

The package is loaded as usual, like any other LaTeX package:

\usepackage{mdframed}

I recommend to load mdframed after xcolor.

The drawing method (default LaTeX commands, TikZ or PSTricks) must be chosen by setting the optional argument of \usepackage:

\usepackage[framemethod=default]{mdframed} % default setting
\usepackage[framemethod=tikz]{mdframed}
\usepackage[framemethod=pstricks]{mdframed}

All other options can be set by using the command \mdfsetup. Of course, mdframed offers more possibilities to set environments with special settings.

To set a special key you can just call

\mdfsetup{leftmargin=12pt}

Then you simple use:

\begin{mdframed}
CONTENTS
\end{mdframed}

To see all allowed keys, please have a closer look at the documentation.

Examples

I created some examples files listed below. Through the examples are drawn with different framemethod's, you can easily adapt them.

\tikzset{
warningsymbol/.style={
rectangle,draw=red,
fill=white,scale=1,
overlay}}
\mdfdefinestyle{warning}{%
hidealllines=true,leftline=true,
skipabove=12,skipbelow=12pt,
innertopmargin=0.4em,%
innerbottommargin=0.4em,%
innerrightmargin=0.7em,%
rightmargin=0.7em,%
innerleftmargin=1.7em,%
leftmargin=0.7em,%
middlelinewidth=.2em,%
linecolor=red,%
fontcolor=red,%
firstextra={\path let \p1=(P), \p2=(O) in ($(\x2,0)+0.5(0,\y1)$)
node[warningsymbol] {\$};},%
secondextra={\path let \p1=(P), \p2=(O) in ($(\x2,0)+0.5(0,\y1)$)
node[warningsymbol] {\$};},%
middleextra={\path let \p1=(P), \p2=(O) in ($(\x2,0)+0.5(0,\y1)$)
node[warningsymbol] {\$};},%
singleextra={\path let \p1=(P), \p2=(O) in ($(\x2,0)+0.5(0,\y1)$)
node[warningsymbol] {\$};},%
}
\begin{mdframed}[style=warning]
\ExampleText
\end{mdframed}

gitpic1

\mdfdefinestyle{theoremstyle}{%
linecolor=red,linewidth=2pt,%
frametitlerule=true,%
frametitlebackgroundcolor=gray!20,
innertopmargin=\topskip,
}
\mdtheorem[style=theoremstyle]{definition}{Definition}
\begin{definition}
\ExampleText
\end{definition}
\begin{definition}[Inhomogeneous linear]
\ExampleText
\end{definition}
\begin{definition∗}[Inhomogeneous linear]
\ExampleText
\end{definition∗}

gitpic4

\mdfdefinestyle{theoremstyle}{%
linecolor=red,linewidth=2pt,%
frametitlerule=true,%
apptotikzsetting={\tikzset{mdfframetitlebackground/.append style={%
shade,left color=white, right color=blue!20}}},
frametitlerulecolor=green!60,
frametitlerulewidth=1pt,
innertopmargin=\topskip,
}
\mdtheorem[style=theoremstyle]{definition}{Definition}
\begin{definition}[Inhomogeneous linear]
\ExampleText
\end{definition}
\begin{definition∗}[Inhomogeneous linear]
\ExampleText
\end{definition∗}

gitpic3

\mdtheorem[%
apptotikzsetting={\tikzset{mdfbackground/.append style=%
{top color=yellow!40!white,
bottom color=yellow!80!black},
mdfframetitlebackground/.append style =%
{top color=purple!40!white,
bottom color=purple!80!black}
}},
,roundcorner=10pt,middlelinewidth=2pt,
shadow=true,frametitlerule=true,frametitlerulewidth=4pt,
innertopmargin=10pt,%
]{alternativtheorem}{Theorem}
\begin{alternativtheorem}[Inhomogeneous linear]
\ExampleText
\end{alternativtheorem}

gitpic5

\mdfsetup{splitbottomskip=0.8cm,splittopskip=0cm,
innerrightmargin=2cm,innertopmargin=1cm,%
innerlinewidth=2pt,outerlinewidth=2pt,
middlelinewidth=10pt,backgroundcolor=red,
linecolor=blue,middlelinecolor=gray,
tikzsetting={draw=yellow,line width=3pt,%
dashed,%
dash pattern= on 10pt off 3pt},
rightline=false,bottomline=false}
\begin{mdframed}
\ExampleText
\end{mdframed}

gitpic2

Help

I have a problem! What can I do?

The most important part is to provide a minimal working example (MWE) for me to be able to reproduce the problem. The problems are categorized (bug, feature request or special settings),so please have a look at the next sections to get the best way of report them.

I found a bug! What can I do?

In this case you can fill out a bug report at github. You can also send me an e-mail.

I have a feature request! What can I do?

Use the same method used for reporting bugs.

I want a special setting! What can I do?

I recommend the TeX.sx Q&A site. There you will find high motivated experts of TeX, LaTeX, ConTeXt, and related typesetting systems.