Latest news 2019-11-04: The giveaway of two signed copies of “Quack, quack, quack. Give my hat back!” has closed and the winning entrants have been selected. Thank you to everyone who took part.

4.7 Boxes and Mini-Pages

TeX views everything on a page as a form of box. Each box has an associated width, height and depth, and the boxes are placed together on the page with glue. This is reminiscent of the days of manual typesetting, where each letter or symbol was on a wooden block, and the wooden blocks were glued in place. The simplest form of box is a single letter. Some letters, such as “a” only have a height and width, whereas other letters, such as “y” have a height, width and depth (see Figure 4.3).

For example, the phrase “cabbages and peas” is made up of 15 boxes:

whereas the word “cauliflower” consists of 10 boxes:4.2

More complicated boxes are made up of smaller boxes. We have already encountered one of these more complicated boxes: the tabular environment, discussed in the previous section. This type of box is called a horizontal box, which means that it can go in a line of text. For example:

Here is some text.
\begin{tabular}{cc}
A & B\\
C & D
\end{tabular}
The rest of the line.

produces:

Recall from the previous section that the tabular environment had an optional argument <pos>. This governs the vertical alignment when the tabular environment occurs within a line of text. This can be one of c (centred—the default, as illustrated above), t (top) and b (bottom). For example,

Here is some text.
\begin{tabular}[b]{cc}
A & B\\
C & D
\end{tabular}
The rest of the line.

produces:

Since a box can't be broken across a line of text, you can use the box making command:

\mbox{<text>}

to prevent <text> from spanning a line break.

Example:

Compare:

\raggedright Some text at the beginning of a paragraph. Some text in the middle of the paragraph. Some more text. \par

with:

\raggedright Some text at the beginning of a paragraph. \mbox{Some text in the middle of the paragraph.} Some more text. \par

(If \raggedright had not been used, the text in the \mbox would've spilt out over the edge of the page.)

Another type of box which can again be placed in a line of text, is the minipage environment.

\begin{minipage}[<pos>][<height>]{<width>}

As the name suggests, this environment creates a “mini-page” of the given width.

Example:

Some text.
\begin{minipage}{2in}
This is a mini-page. The text inside it is formatted as usual.

Paragraph breaks can also be used, but there is no indentation by default\footnote{and this is how a footnote appears}.
\end{minipage}
The rest of the line.

which produces:

You can optionally specify a height, and how the mini-page is aligned with the rest of the text. As with the tabular environment, the alignment option <pos> can be one of t (top), c (centred) or b (bottom). The default is c, which is why the above example has the mini-page centred vertically. This can be changed, for example:

Some text.
\begin{minipage}[t]{2in}
This is a mini-page. The text inside it is formatted as usual.

Paragraph breaks can also be used, but there is no indentation by default\footnote{and this is how a footnote appears}.
\end{minipage}
The rest of the line.

which produces

Note that the width can be specified relative to the current line width, using the length register \linewidth. For example,

\begin{minipage}{0.5\linewidth}
will start a mini-page that is half the width of the current line.

There is also a corresponding command

\parbox[<pos>][<height>]{<width>}{<text>}

which behaves in a similar way. So the above example can be rewritten using a \parbox:

Some text.
\parbox[t]{2in}{This is a parbox. The text inside it is formatted as usual.

Paragraph breaks can also be used, but there is no indentation by default.}

The rest of the line.

which produces

You may have noticed that the \footnote command has not been used in the above example. The \parbox command is more restricted than the minipage environment, so you can't use the \footnote command in it. There are also certain environments, such as the list-making environments, that can be used in a minipage but not in a \parbox.

Footnotes

... boxes:4.2
The fl-ligature is a single character, and so is one box not two.

This book is also available as A4 PDF or 12.8cm x 9.6cm PDF or paperback (ISBN 978-1-909440-00-5).

© 2012 Dickimaw Books. "Dickimaw", "Dickimaw Books" and the Dickimaw parrot logo are trademarks. The Dickimaw parrot was painted by Magdalene Pritchett.