20.2 \fbox & \framebox

Synopses, one of:

\fbox{text}
\framebox{text}
\framebox[width]{text}
\framebox[width][position]{text}

Create a box with an enclosing frame, four rules surrounding the text. These commands are the same as \mbox and \makebox except for the frame (see \mbox & \makebox). The \fbox command is robust, the \framebox command is fragile (see \protect).

\fbox{Warning! No work shown, no credit given.}

LaTeX puts the text into a box, the text cannot be hyphenated. Around that box, separated from it by a small gap, are four rules making a frame.

The first two command invocations, \fbox{...} and \framebox{...}, are roughly the same. As to the third and fourth invocations, the optional arguments allow you to specify the box width as width and the position of the text inside that box as position. See \mbox & \makebox, for the full description but here is an example creating an empty box that is 1/4in wide.

\setlength{\fboxsep}{0pt}\framebox[0.25in]{\strut}}

The \strut ensures a total height of \baselineskip (see \strut).

These parameters determine the frame layout.

\fboxrule

The thickness of the rules around the enclosed box. The default is 0.2pt. Change it with a command such as \setlength{\fboxrule}{0.8pt} (see \setlength).

\fboxsep

The distance from the frame to the enclosed box. The default is 3pt. Change it with a command such as \setlength{\fboxsep}{0pt} (see \setlength). Setting it to 0pt is useful sometimes: this will put a frame around the picture with no white border.

{\setlength{\fboxsep}{0pt}%
 \framebox{%
   \includegraphics[width=0.5\textwidth]{prudence.jpg}}}

The extra curly braces keep the effect of the \setlength local.

As with \mbox and \makebox, LaTeX will not break lines in text. But this example has LaTeX break lines to make a paragraph, and then frame the result.

\framebox{%
  \begin{minipage}{0.6\linewidth}
    My dear, here we must run as fast as we can, just to stay in place.
    And if you wish to go anywhere you must run twice as fast as that.
  \end{minipage}}

See Colored boxes, for colors other than black and white.

The picture environment has a version of the \framebox command where the units depend on picture’s \unitlength (see \framebox (picture)).


Unofficial LaTeX2e reference manual