# Grey box code and lists

I've got that code from a website to make grey areas in my LaTeX document.

% http://www.alfredklomp.com/programming/tex/macros/

\long\def\greybox#1{%
\newbox\contentbox%
\newbox\bkgdbox%
\setbox\contentbox\hbox to \hsize{%
\vtop{
\kern\columnsep
\hbox to \hsize{%
\kern\columnsep%
\setlength{\textwidth}{\hsize}%
\vbox{
\parskip=\baselineskip
\parindent=0bp
#1
}%
\kern\columnsep%
}%
\kern\columnsep%
}%
}%
\setbox\bkgdbox\vbox{
\pdfliteral{0.85 0.85 0.85 rg}
\hrule width  \wd\contentbox %
height \ht\contentbox %
depth  \dp\contentbox
\pdfliteral{0 0 0 rg}
}%
\wd\bkgdbox=0bp%
\vbox{\hbox to \hsize{\box\bkgdbox\box\contentbox}}%
\vskip\baselineskip%
}


But it happens that use in conjunction with nested lists, the text is not correctly wrapped.

I'm far a novice in TeX macro, so I would be interested in advices on if I can and how to modify it fits automatically to the page layout. Would a minipage solve this? Or am I bound to make it with manual line breaks?

-

The solution doesn't allow any pagebreaks. You should use a package like framed or mdframed (new version is on the way ;-) I'm working on it. ):

\documentclass{article}
\usepackage{showframe}
\usepackage{framed}
\usepackage{lipsum}
{\endMakeFramed}
\begin{document}
\lipsum[1]
\lipsum
\lipsum[2]
\end{document}

-
I wasn't quite happy with my solution, this looks much better. –  You Jul 20 '11 at 19:21
The benifit of this solution is that it supports page breaks and IIRC verbatim content. –  Martin Scharrer Jul 20 '11 at 20:58
Indeed a better one. –  M'vy Jul 20 '11 at 21:09

Using \colorbox from the color package instead would be better than a plain TeX macro:

\usepackage{color}
\definecolor{lightgray}{gray}{0.75}

\newcommand\greybox[1]{%
\vskip\baselineskip%
\par\noindent\colorbox{lightgray}{%
\begin{minipage}{\textwidth}#1\end{minipage}%
}%
\vskip\baselineskip%
}


The result:

-
The edited version works well :P Thanks! –  M'vy Jul 20 '11 at 15:52