11

I use mdframed for my theorems like this

\mdfdefinestyle{theoremstyle}{%
  %adjustable lengths
  %inner margins
  innertopmargin=\topskip,
  % outter margins
  skipabove= 0.1in,
  skipbelow= 0.1in,
  % colrs
  linecolor=red!60,
  middlelinewidth=2pt,%
  roundcorner=5pt,
  apptotikzsetting={\tikzset{mdfframetitlebackground/.append style={%
  shade,left color=white, right color=blue!20}}},
  % Title
  frametitlefont=\TheoremHeaderFont\bfseries,
  frametitlerule=true,%
  frametitlerulecolor=orange!60,
  frametitlerulewidth=2pt,
  % Miscellaneous
  nobreak=false,
}

Sometimes page break occurs right after the theorem title. How I can prevent to break the frame between title and content?

EDIT BY yori. I'm having the same problem, so here is a MWE:

\documentclass{article}

\usepackage{lipsum}
\usepackage{mdframed}
\usepackage[a4paper,margin=1.75in]{geometry}

\begin{document}
\lipsum[1-5]

\begin{mdframed}[frametitle={The title}]%
\[
x^2+y^2=z^2.
\]
\end{mdframed}

\end{document}
10
  • Can you add a minimal, compilable example (MWE) that demonstrates the issue? Sep 16, 2014 at 22:32
  • The issue is that when the frame start near the end of the page and page break occurs between the title and content of the frame. I want to prevent this from happening.
    – itun
    Sep 16, 2014 at 23:37
  • I know what the issue is, but it'll be a little hard for us to test that it works unless we have an example where it doesn't. Sep 17, 2014 at 3:17
  • Please add a full MWE that illustrates your problem. It will be much easier for us to reproduce your situation and find out what the issue is when we see compilable code, starting with \documentclass{...} and ending with \end{document}, not just a snippet.
    – Aradnix
    Sep 17, 2014 at 5:38
  • @Aradnix: I just added a MWE for itun because I'm having the same problem. I also added a working but slightly unsatisfactory solution.
    – yori
    Sep 27, 2014 at 11:00

1 Answer 1

5

UNSATISFACTORY ANSWERS:

One way to solve this problem is to use the needspace option:

\documentclass{article}

\usepackage{lipsum}
\usepackage{mdframed}
\usepackage[a4paper,margin=1.75in]{geometry}

\begin{document}
\lipsum[1-5]

\begin{mdframed}[needspace=6em, frametitle={The title}]%
\[
x^2+y^2=z^2.
\]
\end{mdframed}

\end{document}

This tells mdframed to place the first page break at least 6em (vertically) into the frame. It is a bit of an unsatisfactory solution though, because it does not really express the intention, and it needs manual tweaking in the case of multi-line titles.

A second approach is to emulate the title, and add a \nobreak after the title:

\documentclass{article}

\usepackage{lipsum}
\usepackage{mdframed}
\usepackage[a4paper,margin=1.75in]{geometry}

\begin{document}
\lipsum[1-5]

\begin{mdframed}
\textbf{The title} \\ \nobreak
\[
x^2+y^2=z^2.
\]
\end{mdframed}

\end{document}

This works better, but still breaks in certain cases...

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .