# Split mdframed environment occasionally skips page

I'm currently using the mdframed package for a custom environment for my master's thesis. In rare cases, the environment shows some rather strange behaviour — the correctly split environment (i.e. the two, or sometimes even three parts) skips a page!

What I mean by that is, that the environment gets split as it should be, into two or sometimes three parts. However, the first part is not printed on the page were it should be, but on the next page. The second part is then printed on the subsequent page, and so on.

I've been trying to re-create this behaviour for a MWE, but I haven't succeeded yet. I cannot post the LaTeX code of my thesis, but I could post part of the PDF which shows this unwanted behaviour.

The definition of my custom environment might help though — it is largely based on an answer to one of my other questions (see Combining tikzpicture and lstlisting).

\usepackage[framemethod=TikZ]{mdframed}

\makeatletter
\define@key{mdf}{title}{%
}

\mdfdefinestyle{nicebox}{%
innertopmargin=16pt,
innerbottommargin=8pt,
middlelinewidth=.8pt,
outerlinewidth=4pt,outerlinecolor=white,
innerleftmargin=10pt,
innerrightmargin=10pt,
leftmargin=-4pt,rightmargin=-4pt,
skipabove=\topskip,
skipbelow=\topskip,
roundcorner=4pt,
singleextra={\node[draw, fill=white, thick, anchor=west, xshift=10pt+1pt, font=\bfseries] at (O|-P) {\csname mdf@@codeheading\endcsname \space \theboxnumber};},
firstextra={\node[draw, fill=white, thick, anchor=west, xshift=10pt+1pt, font=\bfseries] at (O|-P) {\csname mdf@@codeheading\endcsname \space \theboxnumber};}
}

\newenvironment{boxenv}[2]{%
\incboxnumber
\label{#2}
\bigskip
\mdframed[style=nicebox,title={#1}]
}{\endmdframed}

-
I don't quite understand your question. Can you post a picture of what is happening? – dustin May 17 '13 at 19:03
Of course you get the a bad break. The firstextra material isn't in the calculation of the page dimension. Whether you defined the material as overlay you you must modify the dimension splittopskip. – Marco Daniel May 17 '13 at 19:07
@dustin I uploaded the PDF to my webspace (redpanda.nl/BoxSplines.pdf), see Example 3.18 on page 12. – Ailurus May 17 '13 at 19:22
@Ailurus Marco Daniel will probably be your best resource for this issue. – dustin May 17 '13 at 19:27
Can you drop me an email with your tex files? – Marco Daniel May 17 '13 at 21:09

The height of the defined node isn't part of the calculation and so there is an extra vertical skip which results to an unwanted page break. The easiest way to fix this issue is by adding the option overlay to the node definition. In this way the extra vertical skip is ignored.