Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I use the following custom environment emailHeader and macros to format an email header (credits belong to egreg).

\definecolor{emailHeaderBackground}{RGB}{225,225,225}
\usepackage[framemethod=tikz]{mdframed}
\newmdenv[
  skipabove=0em,
  skipbelow=1em,
  hidealllines=true,
  backgroundcolor=emailHeaderBackground,
  roundcorner=3pt]
  {emailHeader}

In the document ...

\begin{emailHeader}
  \emailFrom[John Doe]{john.doe@stackexchange.com}
  \emailSubject{Re: Please do break apart}
  \emailDate{Wed, 22 Aug 2012 12:23:18 +0200}
  \emailTo[Jane Doe]{jone.doe@stackexchange.com}
  \begin{emailsCc}
    \email[Barack Obama]{barack.obama@whitehouse.gov}
    \email[Michelle Robinson]{michelle.robinson@whitehouse.gov}
  \end{emailsCc}
\end{emailHeader}

The output looks like this ...

E-Mail header

I use the environment several hundred times in the document. Sometimes it happens that the email header is at the end or beginning of a page. Then, it breaks into separate lines. As you can see the environment is not a verbatim environment for which I found settings to avoid the page break.

Question:

How can I prevent a pagebreak for the above environment?
I want the command to be added to the environment definition. I do not want to edit all the places where I use the set of commands.

share|improve this question

1 Answer 1

up vote 4 down vote accepted

To prevent any environment created by mdframed from splitting you can use the option nobreak=true. In your case change the definition of emailHeader to:

\definecolor{emailHeaderBackground}{RGB}{225,225,225}
\usepackage[framemethod=tikz]{mdframed}
\newmdenv[
  skipabove=0em,
  skipbelow=1em,
  hidealllines=true,
  backgroundcolor=emailHeaderBackground,
  roundcorner=3pt,
  nobreak=true]%
  {emailHeader}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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