Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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 ?

share|improve this question
5  
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
add comment

1 Answer

up vote 6 down vote accepted
\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}
share|improve this answer
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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.