Next: , Previous: , Up: Commands for color   [Contents][Index]


21.3.3 Colored boxes

Synopses:

\colorbox{name}{...}
\colorbox[model name]{box background color}{...}

or

\fcolorbox{frame color}{box background color}{...}
\fcolorbox[model name]{frame color}{box background color}{...}

Make a box with the stated background color. The \fcolorbox command puts a frame around the box. For instance this

Name:~\colorbox{cyan}{\makebox[5cm][l]{\strut}}

makes a cyan-colored box that is five centimeters long and gets its depth and height from the \strut (so the depth is -.3\baselineskip and the height is \baselineskip). This puts white text on a blue background.

\colorbox{blue}{\textcolor{white}{Welcome to the machine.}}

The \fcolorbox commands use the same parameters as \fbox (see \fbox & \framebox), \fboxrule and \fboxsep, to set the thickness of the rule and the boundary between the box interior and the surrounding rule. LaTeX’s defaults are 0.4pt and 3pt, respectively.

This example changes the thickness of the border to 0.8 points. Note that it is surrounded by curly braces so that the change ends at the end of the second line.

{\setlength{\fboxrule}{0.8pt}
\fcolorbox{black}{red}{Under no circumstances turn this knob.}}

Unofficial LaTeX2e reference manual