1

I have an environment that I use to format examples in a document I'm writing. The contents of that environment typically consists of a few short paragraphs, often each only a line or two long. I sometimes find one line separated on the next or previous page, but because the lines are usually one-line paragraphs, LaTeX doesn't consider them widows or orphans, so \clubpenalty and \widowpenalty don't apply.

What I'd like to do is have LaTeX consider the whole of the environment to be a single paragraph for the purpose of penalising widows and orphans; or add an additional penalty to any page breaks that fall within the environment. I don't expect them to stop entirely, but I'm seeing plenty of breaks that I'm sure LaTeX could avoid if it knew to do so.

Not sure that a MWE really adds anything, but here's one anyway.

\documentclass[a4paper]{article}

\usepackage{mdframed,parskip,color,xcolor,lipsum}
\mdfsetup{leftmargin=2em,linewidth=3pt,
  rightline=false,topline=false,bottomline=false,
  skipabove=1em,skipbelow=0.25em}

\definecolor{examplebg}{HTML}{E9FBE9}
\definecolor{exampleln}{HTML}{9999FF}
\newmdenv[backgroundcolor=examplebg,linecolor=exampleln]{examplebox}
\newenvironment{example}{\begin{examplebox}%
  \textit{Example} --- \ignorespaces}%
  {\end{examplebox}}

\begin{document}
\lipsum
\begin{example}
\lipsum
\end{example}
\lipsum
\end{document}
  • Do you mean you want to prevent page breaks within the environment? – Steven B. Segletes May 6 '16 at 14:07
  • 1
    Preventing them is easy. Just use minipage. No, I want to penalise them, so they're less likely to occur. – richard May 6 '16 at 14:09

Your Answer

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

Browse other questions tagged or ask your own question.