About
Shop
LaTeX
Software
Books
Gallery
News
Contact
Blog
Settings
Latest news 2019-12-05: new blog post "RSS Feeds and Other Notifications."


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).

Figure 4.3: TeX Views Each Letter as a Box
 
Image of the letters y and a illustrating their
height depth and width. The letter a has zero depth as it does not
extend below the baseline.

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

c a b b a g e s a n d p e a s
whereas the word “cauliflower” consists of 10 boxes:4.2
c a u l i fl-ligature o u r

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:

Image illustrating the typeset output: the tabulated
material is centred vertically within the line of text.

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:

Image illustrating the typeset output: the last row
of the tabulated material rests on the baseline of the text outside it.

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

Image of typeset output: paragraph is left-justified

with:

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

Image of typeset output: line break occurs at the
start of the second sentence leaving a large white space at the end
of the first line.

(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:

Image: the contents of the minipage including
footnote have been typeset in a rectangular block within the outer
line of text.

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

Image: as previous example but the first line of the
minipage is aligned with the outer text.

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

Image: as previous example but without a footnote

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.

Terms of Use Privacy Policy Cookies Site Map FAQs