# How to prevent pagebreak for a custom environment?

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,
roundcorner=3pt]


In the document ...

\begin{emailHeader}
\emailFrom[John Doe]{john.doe@stackexchange.com}
\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}


The output looks like this ...

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.

-

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,