12

I use mdframed to make boxes and split them across pages. However, sometimes mdframed splits! very strangely across the pages. In this example he prefers splitting, while there is enough space to put it all.

enter image description here

I would like to know where the conflict is. I am not interested to tweaking this example, because I have hundreds of boxes. I need to understand where the problem is and fix it in the whole book at once.

\documentclass[a4paper,10pt,twocolumn]{book}
\usepackage[english]{babel}
\newcommand{\mytext}{uutien gaaaetlmsl t n.tu aii s liwmuarpulfoaf ealiesnPui sutuacttcuMitai   ibioErertix}
\usepackage[framemethod=tikz]{mdframed}
\tikzstyle{titregris} =[draw=gray, thick, fill=white,
  text=black, rectangle,minimum height=0.7cm]
\mdfdefinestyle{Argumentstyle}{}
\begin{document}
${}$ \vspace{18cm}
\begin{mdframed}[style=Argumentstyle,
firstextra={\node[titregris,xshift=5mm] at (P-|O) {puttetuiroe};},]
\begin {enumerate}
\item \mytext \mytext
\item \mytext \mytext
\item \mytext \mytext
\item \mytext \mytext
\item \mytext \mytext
\end {enumerate}
\end{mdframed}
\end{document} 

UPDATE: I saw that the wrong breakings take place when there is empty space before. mdframed seems to calculate the empty space needed, correctly splits the box such that the first part has the right length, but then it starts WRONGLY, ALWAYS, from the beginning of the next page! Here is a screen shot!

UPDATE 2: I think now that the problem is given by the node that defines the title of the box. Namely, it gives extra height which does not fit into calculations... I changed the present form of the title with the usual one (frametitlerule=true, frametitle={MyTitle}), and the problem dissapeared in all the document :) However, I do like the node of the previous form...

UPDATE 3: It seems to be indeed from the title box, which goes up few millimeters and mdframed does not take into account for the calculation of available space. The only workaround I found until now was to move the title box INSIDE the main box... I checked, with this the whole document is OK.

  • I have a similar problem and am wondering if there's a way to add more space to mdframed for the calculation. It seems that a raised title-box (the one I'm using is an example of the documentation) is throwing the page-break calculations offs. skipabove and topinnermargin do somehow help, but the values need to be very high before it works consistently, leading to ugly spacing. – badroit Sep 3 '14 at 16:26
  • @badroit Can you provide more details, e.g. an example that is not working for you. – Andrew Swann Sep 4 '14 at 12:23
  • @Andrew, the OP's question refers to the same problem I'm having and his MWE fits well. I have a similar situation in a book with lots of such mdframed environments. Your solution to add skipabove and topinnermargin helps some cases (including the MWE), but for others the skipabove and topinnermargin need to be set very high ... it seems to be a partial workaround rather than a solution. The core problem specifically seems to be that mdframed doesn't take the height of the raised title box into account when calculating the page-break. – badroit Sep 4 '14 at 18:15
4
+50

You can reserve space for the title block with skipabove and topinnermargin. Additionally it turns out that you should hide the size of this title box by setting a bounding box of zero size. This improves breaking across columns:

Sample output

\documentclass[a4paper,10pt,twocolumn]{book}

\usepackage[english]{babel}

\newcommand{\mytext}{uutien gaaaetlmsl t n.tu aii s liwmuarpulfoaf ealiesnPui sutuacttcuMitai   ibioErertix}

\usepackage[framemethod=tikz]{mdframed}
\tikzstyle{titregris}=[draw=gray, thick, fill=white,
  text=black, rectangle, minimum height=0.7cm]
\mdfdefinestyle{Argumentstyle}{}

\begin{document}

\vspace*{18cm}

\begin{mdframed}[style=Argumentstyle,
  skipabove={1.2\baselineskip},
  innertopmargin={1.2\baselineskip},
  firstextra={\useasboundingbox (P) rectangle (P); \node[titregris,xshift=5mm] at (P-|O)  {puttetuiroe};},
  singleextra={\useasboundingbox (P) rectangle (P); \node[titregris,xshift=5mm] at (P-|O)  {puttetuiroe};}]
\begin {enumerate}
\item \mytext \mytext
\item \mytext \mytext
\item \mytext \mytext
\item \mytext \mytext
\item \mytext \mytext
\end {enumerate}
\end{mdframed}

\mytext

\begin{mdframed}[style=Argumentstyle,
  skipabove={1.2\baselineskip},
  innertopmargin={1.2\baselineskip},
  firstextra={\useasboundingbox (P) rectangle (P); \node[titregris,xshift=5mm] at (P-|O)  {puttetuiroe};},
  singleextra={\useasboundingbox (P) rectangle (P); \node[titregris,xshift=5mm] at (P-|O)  {puttetuiroe};}]
\begin {enumerate}
\item \mytext \mytext
\item \mytext \mytext
\item \mytext \mytext
\item \mytext \mytext
\item \mytext \mytext
\end {enumerate}
\end{mdframed}
\end{document} 

Incidentally, note the use of \vspace* rather than ${}$ \vspace. The star * means that the space is not to be discarded at page boundaries etc.

With \vspace*{20cm} the output is:

Second output

  • Note that this solution doesn't work if you set vspace to 18cm (per the OP) rather than 20cm. – badroit Sep 4 '14 at 18:17
  • Setting a bounding box of zero size fixes this. I have updated my answer. – Andrew Swann Sep 5 '14 at 9:41
  • Okay, this works thanks! The next problem, however, is that if the example appears at the top of the page, the title-box pops above the top margin. – badroit Sep 5 '14 at 16:42
  • @badroit You could add outerlinewidth=0.35cm,outerlinecolor=white, but this will also make environment narrow. I don't if that is acceptable. – Andrew Swann Sep 5 '14 at 18:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.