# boxes spanning several pages

I defined some time ago a box environment with the following features:

• It has a frame-color and a background color
• It stores the marginnotes, if any, and restore them at the end of the box. I use for this the commands \mpgmpar@savemarginpars and \mpgmpar@restoremarginpars from the package minipage-marginpar

It worked "perfectly", but now i need to put a very long text in these boxes, and there is not page break. My actual code, which is clearly far from optimal, is :

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{blindtext}
\usepackage{xcolor}
\usepackage{minipage-marginpar}
\usepackage{fancybox}

\newcommand{\strokecolor}{}
\newcommand{\fillcolor}{}
\newlength{\currentparskip}

\makeatletter
\newenvironment{mabox}[3]{%
\renewcommand{\strokecolor}{#2}
\renewcommand{\fillcolor}{#3}
\begin{Sbox}%
\setlength{\currentparskip}{\parskip}% save the value of paragraph skip
\begin{minipage}{#1}%
\setlength{\parskip}{\currentparskip}% restore the value
\mpgmpar@savemarginpars
}%
{\end{minipage}\end{Sbox}\fcolorbox{\strokecolor}{\fillcolor}{\TheSbox} mpgmpar@restoremarginpars}
\makeatother

\begin{document}

\begin{mabox}{10cm}{blue}{gray}
0000

\blindtext \blindtext

11111

\blindtext \blindtext

2222

\blindtext \blindtext

3333

\blindtext \blindtext
\end{mabox}
\end{document}


So, how could I modify the definition of mabox, so that I keep the present features, and that the box would span several pages if the content is very long ?

-
mdframed package is good for boxes of this sort (you'll find many examples on this site) –  David Carlisle Mar 5 '12 at 12:01
possible duplicate of How to continue the framed text box on multiple pages? –  diabonas Mar 5 '12 at 12:19

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{blindtext}
\usepackage{xcolor}

\usepackage[style=1,leftmargin=0pt,rightmargin=0pt]{mdframed}

\makeatletter

\newenvironment{boxtype1}{%
\begin{mdframed}%
[linewidth=.5,margin=8.5,backgroundcolor=gray!20,linecolor=black,fontcolor=black]%
\fontsize{9}{12}\sffamily\selectfont%
}{\end{mdframed}}

\makeatother

\begin{document}

\begin{boxtype1}
0000

\blindtext \blindtext

11111

\blindtext \blindtext

2222

\blindtext \blindtext

3333

\blindtext \blindtext

\end{boxtype1}

\end{document}

-
Welcome to TeX.sx! Could you please add some explanation to your code example to make it easer for others to understand and adapt your solution? –  diabonas Mar 5 '12 at 12:17