[Tex/LaTex] Shaded with “continue on next page”

framedpage-breaking

I am using the shaded environment in the framed package to wrap some text lines that may go across two different pages. If there is a crossing of pages, I'd like to automatically add a line "(continue on next page)" to the first shaded box. Is there an easy way to do so? Thank you.

Best Answer

I recommend to use the newer mdframed package instead of the framed package. However, it also doesn't seem to have such a feature, but it might be done by patching \md@putbox@first and \md@putbox@middle.

Here something quick and dirty:

\documentclass{article}

\usepackage{mdframed}
\usepackage{lipsum}
\usepackage{xcolor}

\makeatletter
\let\orig@md@putbox@first\md@putbox@first
\def\md@putbox@first{%
    \orig@md@putbox@first
    \nopagebreak
    \vspace{-\baselineskip}%
    \vbox to 0pt{\hbox to \linewidth{\hss(continue on next page)}\vss}%
}
\let\orig@md@putbox@middle\md@putbox@middle
\def\md@putbox@middle{%
    \orig@md@putbox@middle
    \nopagebreak
    \vspace{-\baselineskip}%
    \vbox to 0pt{\hbox to \linewidth{\hss(continue on next page)}\vss}%
}
\makeatother

\begin{document}
\lipsum[1]

\bigskip

\begin{mdframed}[backgroundcolor=gray]
\lipsum[1-30]
\end{mdframed}
\end{document}

Result