mdframed package + align gives extra vertical space

I think I may have stumbled upon a bug in the mdframed package. I have an mdframed environment with just one align environment inside it. Consider this minimum working example:

\documentclass[11pt]{article}

\usepackage{amsmath}
\usepackage{mdframed}
\usepackage{blindtext}

\begin{document}
\blindtext \\ \blindtext \\ \blindtext

\begin{mdframed}
\begin{align*}
x^2 + y^2 = z^2 \\
x^2 + y^2 = z^2 \\
x^2 + y^2 = z^2 \\
x^2 + y^2 = z^2 \\
x^2 + y^2 = z^2 \\
x^2 + y^2 = z^2
\end{align*}
\end{mdframed}

\end{document}


This gives the following output:

As you can see, the \begin{mdframed} command is issued around the bottom of the page. Because align is not splittable, the whole frame plus contents gets placed on the next page, which is absolute what expect to happen. However, extra vertical white space appears on the bottom inside the mdframed environment, so that the mdframed environment is much higher than it should be.

From experimenting a bit, I think that the amount of extra white space is about the same amount of remaining vertical space on the previous page, which implies that the mdframed could be up to twice as high as it should be.

Is there a workaround for this?

The environment align isn't a splittable material by default. So you run into an loop which produce such unwanted space. However at the moment I am working on a fix. I think I will upload the new version at the weekend (inspired by Nicolas Markey).

To fix this with the current version use the following example which uses the command \allowdisplaybreaks to make align splitable.

\documentclass[11pt]{article}

\usepackage{amsmath}

\usepackage{mdframed}
\usepackage{blindtext}

\begin{document}
\blindtext \\ \blindtext \\ \blindtext

\allowdisplaybreaks
\begin{mdframed}
\rule{\linewidth}{0pt}
\begin{align*}
x^2 + y^2 = z^2 \\
x^2 + y^2 = z^2 \\
x^2 + y^2 = z^2 \\
x^2 + y^2 = z^2 \\
x^2 + y^2 = z^2 \\
x^2 + y^2 = z^2
\end{align*}
\end{mdframed}

\end{document}


• Thanks for your reply, and thanks also for this great package! I will patiently wait for your new version then. In the mean time, adding the \allowdisplaybreaks is actually not such a bad idea. – yori Apr 25 '12 at 19:47