3

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
\def\mdf@@codeheading{Default}%
\define@key{mdf}{title}{%
   \def\mdf@@codeheading{#1}
}

\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}
Ailurus
  • 1,163

1 Answers1

4

The OP dropped me an email.

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.

Marco Daniel
  • 95,681