# TikZ mdframed environment: close box at end of page and continue on next

I used the Excursus environment as a template to create my own box like this:

\usepackage[style=1,leftmargin=0pt,rightmargin=0pt,framemethod=TikZ]{mdframed}
\newenvironment{boxtype1}{%

\begin{mdframed}%

[linewidth=.5,margin=8.5,backgroundcolor=gray!2,linecolor=red,fontcolor=black,roundcorner=10pt, middlelinewidth=2pt]%

\fontsize{12}{14}\sffamily\selectfont%
}{\end{mdframed}}


Works perfectly nice. However, would there be a way to automatically close the box at a page break and then open it new on the next one? If it would even be possible to have a "Excursus X continued" on each page that would be perfect.

Thanks

Philipp

• Please provide a complete, compilable example. That is much more useful than a mere fragment of code and will encourage people to answer your question!
– cfr
Nov 30, 2014 at 17:51
• everyline [untested since no Minimum Working Example provided]
– cfr
Nov 30, 2014 at 17:55

You can use the everyline=true option so that all parts of the mdframed get the whole frame. Using middleextra and secondextra, you can add material for the continuing parts of the mdframed. In the example below I added "Excursus (Cont.)" at the upper left part of the frame in the continuation parts.

The code:

\documentclass{article}
\usepackage[a5paper]{geometry}% just for the example
\usepackage[framemethod=TikZ]{mdframed}
\usepackage{lipsum}

\newenvironment{boxtype1}
{%
\begin{mdframed}[
linewidth=.5,
everyline=true,
%margin=8.5,
backgroundcolor=gray!2,
linecolor=red,
fontcolor=black,
roundcorner=10pt,
middlelinewidth=2pt,
splittopskip=25pt,
secondextra={
\node[
overlay,
fill=white,
anchor=west,
font=\sffamily\large,
inner xsep=10pt
] at ([xshift=10pt]O|-P) {Excursus (Cont.)};
},
middleextra={
\node[
overlay,
fill=white,
anchor=west,
font=\sffamily\large,
inner xsep=10pt
] at ([xshift=10pt]O|-P) {Excursus (Cont.)};
}
]%
\fontsize{12}{14}\sffamily\selectfont%
}
{\end{mdframed}}

\begin{document}

\lipsum[1-2]
\begin{boxtype1}
\lipsum[1-4]
\end{boxtype1}
\lipsum[2]

\end{document}

• Works! And looks awesome. Thanks. One question though, is there a way to control the bottom boundary of the box? The lower part of the letters touch the red line. Or is this my footer, which needs to be changed? Nov 30, 2014 at 21:30
• @user2334921 You're welcome! Regarding your question, you can control the separation between text and the bottom line using innerbottommaring, as in innerbottommaring=40pt. There's also splitbottomskip for the split components of the frame. If this doesn't solve your problem, I'll need to see some minimal, yet complete code illustrating the problem; otherwise, no effective advise can be provided. Dec 1, 2014 at 1:00
• Thanks again @GonzaloMedina. The splitbottomskip does the trick. Sorry for not providing an example. I will do this next time. Cheers Philipp Dec 1, 2014 at 9:59