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

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

    \setbox\contentbox\hbox to \hsize{%
            \hbox to \hsize{%
                \advance\hsize by -2\columnsep%
        \pdfliteral{0.85 0.85 0.85 rg}
        \hrule width  \wd\contentbox %
               height \ht\contentbox %
               depth  \dp\contentbox
        \pdfliteral{0 0 0 rg}
    \vbox{\hbox to \hsize{\box\bkgdbox\box\contentbox}}%

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

TeX Problem with area

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. ):

  \def\FrameCommand{\fboxsep=\FrameSep \colorbox{shadecolor}}%
  \MakeFramed{\advance\hsize-\width \FrameRestore\FrameRestore}}%
  • 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. 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:



The result:

Result of \colorbox command


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.