# mdframed is causing wrong alignment at the bottom of pages

If you would be so kind to compile this LaTeX document:

\documentclass[a4paper,11pt]{book}

\usepackage[paper=a4paper,twoside=true,lmargin=4cm,
rmargin=4cm,bindingoffset=0cm]{geometry}

\usepackage{mdframed,lipsum,kantlipsum}
\mdfsetup{font=\small}

\begin{document}
\kant[1-8]

\begin{mdframed}
\kant[1-5]
\end{mdframed}

\end{document}


You will find that the bottoms of pages 2 and 3 are misaligned as follows:

Questions:

1. Shouldn't the space between the paragraph and the frame on page 3 expand such that the bottoms align? Why does this not take place?

2. How would you add a flexible (zero, plus something flexible if needed, just like for paragraph spacing) space above the mdframed box too? That would put a less strain on the space between the paragraphs, assuming I resolve question 1 above.

-

For reasons I don't understand, mdframed outputs the first (split) box in a way that the page bottom will be ragged no matter whether \raggedbottom or \flushbottom (default with book) is configured.

You can get a more normal behaviour with the following patches:

\usepackage{mdframed}

\makeatletter

\patchcmd\mdf@put@frame@i{\hrule \@height\z@ \@width\hsize\vfill}{}{}{}
\patchcmd\mdf@put@frame@i{\hrule \@height\z@ \@width\hsize\vfill}{}{}{}
\patchcmd\mdf@put@frame@i{\hrule \@height\z@ \@width\hsize\vfill}{}{}{}

\makeatother


As I really don't know what this is supposed to achieve, this will probably break something, but at least, the page bottom is aligned now ;-)

The space above the mdframed box is configured with skipabove, so you get flexible glue by

\mdfsetup{font=\small,skipabove=\parskip}


-
I didn't implement this because I like the alignment at the top ;-) –  Marco Daniel Sep 1 '12 at 7:12
@MarcoDaniel Ah, Ok. That's a valid reason I suppose ;-) Is it documented behaviuor? btw, what exactly do you mean by top alignment? Usually one speaks about top/bottom alignment when things are arranged horizontally. –  Stephan Lehmke Sep 1 '12 at 9:32
I mean the vertical alignment. –  Marco Daniel Sep 1 '12 at 9:34
@MarcoDaniel What do you mean "alignment at the top"? –  MayGodBlessKnuth Sep 1 '12 at 10:58
@MarcoDaniel Of course "top" is a vertical alignment, but normally, vertical alignment only makes sense when things are displayed side by side (like parboxes or tables). –  Stephan Lehmke Sep 1 '12 at 11:12