1

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 ?

6
\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}
  • 4
    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
  • For me, LaTeX objected to the "margin=" option, but allowed leftmargin and rightmargin. – CPBL Jun 1 '16 at 18:32

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.