9

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.

8

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}

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.