CERN Accelerating science

This website is no longer maintained. Its content may be obsolete. Please visit http://home.cern/ for current CERN information.



next up previous
Next: Moving boxes Up: LaTeXeAn Overview Previous: Playing with lengths

Page Markup---Several Kinds of Boxes

Boxes are at the very heart of TeX's basic typesetting paradigm, and LaTeX provides several commands which make it easy to make use of this functionality.

\mbox{text}\makebox[width][pos]{text}

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

In addition to centering the text with positional argument [c] (the default), you can position the text flush left ([l]) or flush right ([r]). LaTeXe also offers you an [s] specifier that will stretch your text from the left margin to the right margin of the box provided it contains some stretchable space. As already mentioned in the previous section, LaTeXe also allows you to make use of four special length parameters inside the width argument of the box commands: width, height, depth, and totalheight. These parameters specify the natural size of the text, where totalheight is the sum of height and depth.

The examples below show how these various parameters are used to control the layout in the box. Note that use is also made of the calc package, which allows arithmetic operations in the arguments of the commands.

\framebox{A few words of advice}             \par
\framebox[\width + 6mm][s]{A few words of advice} 
\par  \framebox[1.5\width]{A few words of advice}

\rule[lift]{width}{total_height}

Rules come in handy for controlling the height of a box. Together with the new LaTeX commands for measuring the height and depth of your boxes, they allow you to perform micro-typographic adjustments for tuning the visual presentation of your document elements.

\newsavebox{\Maybox}\savebox{\Maybox}{\Large May}
\newlength{\Mdp}\settodepth{\Mdp}{\usebox{\Maybox}}
\newlength{\Mht}\settoheight{\Mht}{\usebox{\Maybox}}
\addtolength{\Mht}{\Mdp}

\framebox[1.6\width+1em][s]{\usebox{\Maybox}}
\quad
\framebox[1.6\width+1em][s]{\usebox{\Maybox}%
          \rule[-2\Mdp]{0mm}{2\Mht}}

May

Zero-width boxes are also useful in other circumstances.

\begin{center}
A centred sentence.\makebox[0cm][l]{$^{123}$}\\ 
Some more text in the middle.                 \\ 
\makebox[0cm][r]{$^{321}$}A centred sentence.\\ 
\end{center}
\noindent\makebox[0cm][r]{\(\Leftrightarrow\)}%
As seen in the margin of the current line, boxes 
with a vanishing width can stick out in the margin.



Janne Saarela
Wed May 17 14:38:58 METDST 1995