LaTeX sets everything — text, math, figures — by first packing it into boxes and then arranging the boxes on the page. A box is a rigid rectangle with three dimensions (width, height, depth); the line breaker never looks inside it and treats it as a single, indivisible unit. Once you grasp this “pack it in a box” idea, shifting, overlapping, framing, and building columns all turn out to be variations on one mechanism.
The box model
Inside TeX, every piece of typeset material is a box with dimensions. A single character is a box, a word is a box, a line is a box, and so is a whole page. To build lines and paragraphs, LaTeX glues these boxes together with stretchable space and breaks lines and pages at the best spots. The key point: once material is packed into a single box, its contents are never split again. No line break happens inside the box; the whole thing moves to the next line as one unit.
LaTeX boxes come in two broad kinds. The first is the LR box (left-to-right box): it lays its contents out in a single row and never breaks a line, spilling past the margin if it grows too wide. \mbox, \makebox, and the framed \fbox are LR boxes. The second is the paragraph box: it wraps its contents inside a width you fix in advance, so it can hold several lines and even several paragraphs. \parbox and the minipage environment are paragraph boxes.
This split mirrors TeX’s modes. The inside of an LR box is in LR mode, which streams the input left to right and never breaks. A paragraph box switches into (inner) paragraph mode, where line breaking works just as it does in ordinary body text. Keeping track of which command starts which mode makes it obvious why something refuses to wrap, or why a box grows downward instead.
LR boxes: packing one line
The most basic LR box is **\mbox{...}. It seals its contents into one box and forbids both line breaks and hyphenation**. Wrap a phrase you never want split — a product name like Mac OS X, a phone number, a long chemical name — in \mbox and it will always stay on one line. It is also handy for small fixes, such as keeping a value glued to its unit.
When you want to choose the width yourself, use **\makebox[width][position]{text}**. The [width] sets the box width, and [position] chooses where the contents sit inside it: l flush left, c centered (the default), r flush right, and s stretches the interword spaces so the line is justified to the full width. Besides ordinary lengths like \textwidth, the width may use special lengths that stand for the contents’ natural size: \width (its width), \height and \depth, and \totalheight (height plus depth). So \makebox[2\width]{word} makes a box twice as wide as the word.
Especially powerful is the zero-width box \makebox[0pt][position]{text}. Because the box has width 0, LaTeX typesets the contents but does not advance the horizontal position, so they overprint whatever comes next. With [c] the contents straddle the current point, with [r] they hang to the left, and with [l] to the right. This drives strike-throughs, overstrikes, and notes in the margin; the shorthands \rlap and \llap (zero-width boxes overhanging right and left) work the same way.
To draw a frame, use **\fbox{text} and \framebox[width][position]{text}**, which rule all four sides of the box. \framebox’s [width][position] are exactly those of \makebox. The frame’s look is governed by two lengths: the rule thickness **\fboxrule (default 0.4pt) and the gap between frame and contents \fboxsep (default 3pt)**. Change them with \setlength; e.g. \setlength{\fboxsep}{0pt} makes the frame hug the contents. These are single-line LR boxes, so to frame several lines you combine them with the paragraph boxes below (for fancier frames, see “Frames”).
Do not break \mbox{Mac OS X} here.
% a 4cm box, contents flush right, then framed
\framebox[4cm][r]{right} \\[1ex]
% zero-width box: the word overprints what follows
X\makebox[0pt][l]{\,/} Y % prints an X/ over the gap before YIn the example, the \mbox’d phrase always stays on one line, \framebox[4cm][r] puts its contents flush right inside a 4 cm frame, and the zero-width box overprints a slash right after the X.
Paragraph boxes: parbox and minipage
When you want to fix a width and let the contents wrap, paragraph boxes step in. The lightweight one is **\parbox[position]{width}{text}**, which wraps its contents as a single paragraph inside the given {width}. The [position] says where the box aligns with the surrounding line: c (the default — the box’s center lines up with the line’s center), t (the baseline of the box’s top line aligns with the surrounding baseline), or b (its bottom line’s baseline). You can go further with \parbox[position][height][inner-pos]{width}{text} to set a height and an inner vertical alignment (t/c/b/s), but \parbox only handles a single paragraph — no multiple paragraphs or lists.
The more capable paragraph box is the **minipage environment**: \begin{minipage}[position][height][inner-pos]{width} … \end{minipage}, whose arguments mean the same as \parbox’s, but whose contents behave like a small page of their own. It can hold multiple paragraphs, lists such as itemize, even verbatim — it is the real workhorse among paragraph boxes. One thing to note: inside it the **paragraph indent (\parindent) is reset to 0**; set it yourself with \setlength{\parindent}{1em} if you need it.
A minipage also has its own footnote handling. A \footnote used inside it lands not at the foot of the page but just below the minipage, marked with lowercase letters a, b, … (a dedicated mpfootnote counter). That is convenient when you want a note to stay self-contained within a table or a boxed aside. On the other hand, a minipage cannot contain floats (figure/table) and is never broken across pages — it has to fit on the page as one box.
The most common use of minipages is side-by-side columns. Place two minipages one after another with some space such as \hfill between them, and you get a simple two-column layout — ideal for putting a figure beside its caption, or two images next to each other. Setting both to [t] aligns the tops of two boxes of differing height neatly (for heavier-duty placement, see “Floats & placement”).
\noindent
\begin{minipage}[t]{0.48\textwidth}
Left column. This minipage wraps text within 48\%
of the text width, and can hold several paragraphs,
lists, and even its own footnote.\footnote{Local note.}
\end{minipage}\hfill
\begin{minipage}[t]{0.48\textwidth}
Right column, top-aligned with the left one because
both use the optional \verb|[t]| argument.
\end{minipage}Each minipage takes 48% of the text width, and the \hfill between them soaks up the rest so they span the full measure. Because both carry [t], their tops align even if they have different numbers of lines. The \footnote in the left box appears below the minipage with a lowercase mark, not at the foot of the page.
Shifting and ruling: raisebox and rule
To shift a box vertically, use **\raisebox{lift}[height][depth]{text}**. A positive {lift} raises the contents, a negative one lowers them. The clever part is the optional [height] and [depth]: they tell LaTeX to pretend the box has that much height and depth, so the surrounding line spacing is computed from the declared values rather than from what is actually drawn. For instance \raisebox{0pt}[0pt][0pt]{a big symbol} draws something large while declaring zero height and depth, letting you drop in an ornament without disturbing the leading. The special lengths \height, \depth, and \totalheight work here too.
\rule[lift]{width}{height}** draws a solid filled rectangle (a black box). {width} and {height} set its dimensions, and the optional [lift] shifts it above the baseline (or below, if negative). It is perfect for horizontal lines — \rule{0.5\linewidth}{0.4pt} gives a thin rule half the line width.
The other face of \rule is the strut. A zero-width \rule{0pt}{height} is an invisible box that prints nothing yet reserves that much height, useful for forcing a minimum line height or giving table cells some breathing room. Put \rule{0pt}{2.6ex} at the start of a line and that line is guaranteed to be at least 2.6 ex tall. LaTeX’s own \strut is exactly \rule[-0.3\baselineskip]{0pt}{\baselineskip} — a zero-width strut spanning the full current leading above and below the baseline, the classic fix for keeping text from crowding a table rule.
% a centered horizontal rule
\noindent\hfil\rule{0.5\linewidth}{0.4pt}\hfil
% a strut forces a taller line / roomier table cell
\begin{tabular}{|l|}
\hline
\rule{0pt}{2.6ex}Tall, uncramped row \\
\hline
\end{tabular}
% align two differently sized boxes on a common baseline
big \raisebox{-0.4ex}{\Huge A} smallSaving and reusing boxes
If you reuse the same material repeatedly, you can typeset it once, store it in a box, and just pull it out afterward. First declare a storage box (register) with \newsavebox{\boxname}. Then fill it with \sbox{\boxname}{text} or \savebox{\boxname}[width][position]{text} — and the contents are actually typeset only at this one moment. Wherever you want it, \usebox{\boxname} emits the stored box verbatim. For costly material such as a long table or an intricate figure used in several places, this both speeds up processing and guarantees the appearances match exactly.
A storage box is an LR box, so to keep multi-line material you wrap it in a \parbox or minipage first. There is also an environment form, \begin{lrbox}{\boxname} … \end{lrbox}, which is the better choice for storing contents that include verbatim. Note that \sbox is robust while \savebox is fragile, so take care when using the latter inside a “moving argument” such as a section title.
To measure a box, use \settowidth{\len}{text}, \settoheight{\len}{text}, and \settodepth{\len}{text}, which store the width, height, or depth of the typeset contents into the given length register. They are useful for precise tweaks — drawing a frame or an underline sized exactly to a box.
\newsavebox{\mylogo}
\sbox{\mylogo}{\fbox{\textbf{Draft}}} % typeset once
% reuse the identical box as many times as you like
Header: \usebox{\mylogo} \dots\ Footer: \usebox{\mylogo}
% measure a box into a length, then rule under it
\newlength{\w}
\settowidth{\w}{Signature}
Signature\par\rule{\w}{0.4pt}The \sbox line boxes “Draft” in a frame once, and the two \usebox calls pull out that identical box. In the lower half, \settowidth measures the width of “Signature,” and \rule draws an underline of exactly that width.
The box commands at a glance
| Command | Kind | What it does |
|---|---|---|
\mbox | LR box | Locks contents on one line; no break, no hyphenation |
\makebox | LR box | Sets width and position; [0pt] overprints at zero width |
\framebox | LR box | A framed \makebox (\fbox is the no-width form) |
\parbox | Paragraph box | A single wrapped paragraph at a fixed width |
minipage | Paragraph box | A small page for paragraphs, lists, and footnotes |
\raisebox | Transform | Shifts contents up/down; can fake height and depth |
\rule | Filled box | A solid rectangle; zero width gives a strut |
\usebox | Storage | Emits a box saved via \newsavebox + \sbox |