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'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%
                \advance\hsize by -2\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.

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?

share|improve this question
add comment

2 Answers 2

up vote 6 down vote accepted

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}
\renewenvironment{shaded}{%
  \def\FrameCommand{\fboxsep=\FrameSep \colorbox{shadecolor}}%
  \MakeFramed{\advance\hsize-\width \FrameRestore\FrameRestore}}%
 {\endMakeFramed}
\definecolor{shadecolor}{gray}{0.75}
\begin{document}
\lipsum[1]
\begin{shaded}
\lipsum
\end{shaded}
\lipsum[2]
\end{document}
share|improve this answer
    
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
add comment

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:

Result of \colorbox command

share|improve this answer
    
The edited version works well :P Thanks! –  M'vy Jul 20 '11 at 15:52
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.