1

I apologise in advance because I cannot provide an MWE.

I am writing a book with a custom (Springer) format and I wish to use mdframed to provide an example environment. I adapted an example from the documentation and came up with this as a first draft:


\documentclass{article}
\usepackage{mdframed}
\usepackage{tikz}
\usepackage{blindtext}

\newcounter{exampl}[section]
\newenvironment{exampl}[1][]{%
 \stepcounter{exampl}%
  \ifstrempty{#1}%
  {\mdfsetup{%
    frametitle={%
       \tikz[baseline=(current bounding box.east),outer sep=0pt]
        \node[anchor=east,rectangle,fill=black!10]
        {\strut Example~\thesection .\theexampl};},nobreak=false}
  }%
  {\mdfsetup{%
     frametitle={%
       \tikz[baseline=(current bounding box.east),outer sep=0pt]
        \node[anchor=east,rectangle,fill=black!10]
        {\strut Example~\thesection .\theexampl:~#1};},nobreak=false}%
   }%
   \mdfsetup{innertopmargin=10pt,linecolor=black!10,nobreak=false,%
             linewidth=2pt,topline=true,backgroundcolor=black!05,%
             frametitleaboveskip=\dimexpr-\ht\strutbox\relax}
   \begin{mdframed}[]\relax%
   }{\end{mdframed}}


\begin{document}

\section{Introduction}

\blindtext

\blindtext

\blindtext

\begin{exampl}[Lorem ipsum]
   \blindtext

   \begin{tabular}{cc}
    A & Table\\
   \end{tabular}

   \Blindtext
\end{exampl}

\end{document}

In the MWE provided, the exampl works fine and uses appropriate page-breaks. However, in the context of the source of the book I'm working on, the same environment will not break.

As per the MWE above, I tried explicitly adding nobreak=false everywhere to try force the page-break, but to to avail.

I've tried debugging it and working back towards an MWE, but to no avail. I believe it might be something in the custom book template that's causing the problem.


I know that my problem might not be reproducible and thus is not ideal for this site, but I was hoping someone might be able to offer some common reasons as to why an mdframed environment won't break across pages. I'm hoping for clues to debug the problem.

What are common reasons why page-breaking might stop working in mdframed?

Any tricks to try force page-breaking again?

2
  • 1
    Use the framed package, it breaks across the pages. – skpblack Aug 1 '14 at 19:59
  • Yep, but in theory, mdframed should also break across pages. – badroit Aug 1 '14 at 20:03
2

Ah okay, only a few minutes after asking the question, I found the answer (creating the MWE helped).

The problem was with the picins package loaded (I think) in the template class. If you load picins, the mdframed environments will no longer break over pages, as per this M(N)WE:


\documentclass{article}
\usepackage{picins}
\usepackage{mdframed}
\usepackage{tikz}
\usepackage{blindtext}

\newcounter{exampl}[section]
\newenvironment{exampl}[1][]{%
 \stepcounter{exampl}%
  \ifstrempty{#1}%
  {\mdfsetup{%
    frametitle={%
       \tikz[baseline=(current bounding box.east),outer sep=0pt]
        \node[anchor=east,rectangle,fill=black!10]
        {\strut Example~\thesection .\theexampl};},nobreak=false}
  }%
  {\mdfsetup{%
     frametitle={%
       \tikz[baseline=(current bounding box.east),outer sep=0pt]
        \node[anchor=east,rectangle,fill=black!10]
        {\strut Example~\thesection .\theexampl:~#1};},nobreak=false}%
   }%
   \mdfsetup{innertopmargin=10pt,linecolor=black!10,nobreak=false,%
             linewidth=2pt,topline=true,backgroundcolor=black!05,%
             frametitleaboveskip=\dimexpr-\ht\strutbox\relax}
   \begin{mdframed}[]\relax%
   }{\end{mdframed}}


\begin{document}

\section{Introduction}

\blindtext

\blindtext

\blindtext

\begin{exampl}[Lorem ipsum]
   \blindtext

   \begin{tabular}{cc}
    A & Table\\
   \end{tabular}

   \Blindtext
\end{exampl}

\end{document}

The order of loading the packages doesn't seem to matter either, so either choose page-breaking in mdframed or picins I guess.

Anyways, sorry for the noise but maybe this will help someone who encounters a similar issue later.

2
  • You should accept your answer, so that your question is not recorded as unanswered. – Sveinung Aug 1 '14 at 20:36
  • Okay, I have to wait two days though according to the system. :) – badroit Aug 1 '14 at 20:52

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.