2006
07.16

Gray boxes in latex

I am sure you were wondering how to have boxes in latex with gray background. This is useful if you want to emphesize some text. This is not too hard to do, but since I just figured it out, I decided to provide the details.

The basic idea is to put your text in a minipage, and then encapsulate this inside a colorbox command. The first problem is that minipage for some reason kills the identation, so if you want regular identation, then you need the following stuff

\newlength{\savedparindent}
\newcommand{\SaveIndent}{\setlength{\savedparindent}{\parindent}}
\newcommand{\RestoreIndent}{\setlength{\parindent}{\savedparindent}}

Now, the \InGray command does it all:

\newcommand{\InGray}[1]{%
\SaveIndent{} %
\noindent{}
\fcolorbox[rgb]{0,0,0}{0.95,0.95,0.95}{
\begin{minipage}{0.965\linewidth} %
\RestoreIndent{}%
#1
\end{minipage}
}
}

To use, you will need the \usepackage{color} command. Now, to use just put in the latex file:


bla bla

\medskip

\InGray{
Given a set $\PSet = \brc{P_1, \ldots, P_k}$ of convex polygons in the
plane with total complexity $n$, we are interested in translating the
polygons of $\PSet$ such that some measure is minimized (or
maximized).
}

bla bla

The results look likeâ€¦
!

P.S. There are at least five different ways to do this. Ths is just one possible way.