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:
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:
produces:
produces:
Since a box can't be broken across a line of text, you can use the box making command:
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
\raggedright
Some text at the beginning of a paragraph. \mbox
{Some
text in the middle of the paragraph.} Some more text.
\par
\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.
As the name suggests, this environment creates a “mini-page” of the given width.
Example:
\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:
\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,
There is also a corresponding command
which behaves in a similar way. So the above example can be
rewritten using a \parbox
:
\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
\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).