# Inconsistent horizontal width of mdframed with only display math content

Update 2012-03-09: With an version of mdframed updated today, this is now fixed in the package and no longer requires the workaround provided below.

In Excess vertical space in mdframed ending with display math environment, I had wrapped the contents on mdframed within a minipage and had intended to file this as a separate question, as I believe that the minipage wrapper should not be necessary. Without this wrapper, if the content contains only display math, the width is not the full \linewidth.

Here is a snippet of the output showing the inconsistent output for the case of display math in red. Note that the output is fine if the frame has a title, but without the frame the width is not consistent:

## Questions:

• Is there a mdframed setting to adjust this? If not, is there any better way to get the desired behavior other than using a minipage?
• Is this a bug with mdframed, or a feature?

## Code:

\documentclass{article}
\usepackage{showframe}
\usepackage{amsmath}

\usepackage[framemethod=TikZ]{mdframed}
\newenvironment{Frame}[1][]{%
\begin{mdframed}[%
frametitle={#1},
skipabove=\baselineskip plus 2pt minus 1pt,
skipbelow=\baselineskip plus 2pt minus 1pt,
linewidth=0.5pt,
frametitlerule=true,
frametitlebackgroundcolor=gray!30
]%
%\begin{minipage}{\linewidth}%  this should not be necessary??
}{%
%\end{minipage}%
\end{mdframed}
}

\begin{document}\noindent
Text
\begin{Frame}[with Title]
Text
\end{Frame}
Text
\begin{Frame}% no Title
Text
\end{Frame}
Text
\begin{Frame}[Einstein]
\begin{align*}
e & = mc^2
\end{align*}
\end{Frame}
Text
\begin{Frame}\color{red}% no Title
\begin{align*}
e & = mc^2
\end{align*}
\end{Frame}
Text
\begin{Frame}\color{red}% no Title
\begin{align*}
e  &= mc^2\\
F  &= ma
\end{align*}
\end{Frame}
Text
\begin{Frame}\color{red}% no Title
$e = mc^2$
\end{Frame}
\end{document}


I wouldn't use a minipage as that stops breaking the frame, which is, presumably the main point of the mdframed frame, Between the tikz and the German I'm not sure whether it's a bug or (like minipage) it is a feature. A standard LaTeX minipage will similarly ignore its requested length and just use the natural length of its content if its content is just vertical material. (This is documented as working if you put a tabbing in minipage but it is generally true. So I'd just force the width by putting a rule in:

\newenvironment{Frame}[1][]{%
\begin{mdframed}[%
frametitle={#1},
skipabove=\baselineskip plus 2pt minus 1pt,
skipbelow=\baselineskip plus 2pt minus 1pt,
linewidth=0.5pt,
frametitlerule=true,
frametitlebackgroundcolor=gray!30
]%
\hrule height0pt width\hsize\relax%<<<<<<<<<<<<<<FORCE WIDTH
%\begin{minipage}{\linewidth}%  this should not be necessary??
}{%
%\end{minipage}%
\end{mdframed}
}

• The width is lost if the frame does break over a page, you could put the rule in again before the mdframe ends, but that still doesn't catch multiple page cases. mdframe.sty already inserts a similar rule in lots of places, but I think it needs a few more, can't spot where at present though. – David Carlisle Mar 3 '12 at 19:57
• @PeterGrill: Fixed in the new version. – Marco Daniel Mar 4 '12 at 10:16
• @MarcoDaniel:Great. Once it is released, please post an answer here. – Peter Grill Mar 4 '12 at 17:56
• @PeterGrill: Do read also the rss feed of CTAN ;-). It works now. I think a small editing of your question is enough. Please test the new version. – Marco Daniel Mar 4 '12 at 17:59
• @MarcoDaniel: This is now confirmed fixed in the package. Have updated the question to reflect this. Thanks for the quick turnaround. – Peter Grill Mar 10 '12 at 1:19