Nearly every tool for fine-tuning mathematics in LaTeX comes from one idea: separate how something looks from the dimensions it occupies — its height, depth and width. \smash makes a tall thing count as zero height, \vphantom reserves height while printing nothing, and \rlap prints a character while taking zero width. That is why symptoms like “the one line with a radical in it has wider leading”, “two adjacent \sqrt signs do not line up at the top” and “a condition under a summation stretches the formula sideways” all yield to the same way of thinking. This page is arranged by symptom, setting out \smash, \phantom, \mathstrut, \rlap, \raisebox and the difference between \mathrm and \operatorname, with measured figures throughout.
Find the tool by symptom
Here is the index. Every one of these is a tool for tidying the printed result at the last moment, and none of them changes what a formula means. So the right order of work is to write the mathematics plainly first and apply these only where a visible blemish actually appears. Scattering \smash and \phantom pre-emptively backfires the moment you change the font or the text width. The command in the first column is also the search term, so start from the symptom and look across.
| Command | Symptom it fixes | Comes from |
|---|---|---|
\smash | a tall element spreads that one line apart from its neighbours | LaTeX kernel ([t] / [b] from amsmath) |
\vphantom | adjacent radicals or rows do not reach the same height | plain TeX, available as-is in LaTeX |
\mathstrut | the same, with no argument: reserves one parenthesis worth of height | plain TeX; its definition is literally \vphantom( |
\phantom | you want columns to line up across lines but the left sides differ in length | plain TeX; for width only, \hphantom |
\mathclap | a long condition under a sum or product widens the whole formula | mathtools (\mathllap / \mathrlap are in the same set) |
\rlap | you want to print something without it counting toward the width | plain TeX; \llap overhangs to the left |
\overset | you want an arbitrary symbol squarely above an = or similar | amsmath (\underset for below) |
\operatorname | a multi-letter operator of your own gets no spacing around it | amsmath; \operatorname* puts limits below |
\raisebox | one element needs to move up or down by a fixed amount | LaTeX kernel; it can override height and depth too |
\! | symbols sit too far apart, as in a double integral \int\int | plain TeX; the exact inverse of \,, at −3mu |
The one line with a radical in it has wider leading — \smash
\smash{...} makes TeX treat its contents as a box of zero height and zero depth. The ink still prints, but because TeX sees no vertical size it stops deciding to widen the leading. Measured, $\sqrt{1-x^2}$ is 9.13329pt high, 1.26668pt deep and 35.75691pt wide. Wrap it in \smash and it becomes 0.0pt high and 0.0pt deep, with the width still 35.75691pt. The numbers show plainly that only the vertical is zeroed and the horizontal is left completely alone.
% the radical inside the fraction pushes this line away from the one above
$y = \frac{1}{\sqrt{1 - x^2}}$
% zero its vertical size, and the leading returns to normal
$y = \frac{1}{\smash{\sqrt{1 - x^2}}}$Load amsmath and \smash gains an optional argument that lets you treat top and bottom separately. \smash[t]{...} zeroes only the height, leaving the depth; \smash[b]{...} zeroes only the depth, leaving the height. Measured, \smash[t]{\sqrt{1-x^2}} came out 0.0pt high and 1.26668pt deep, and \smash[b]{\sqrt{1-x^2}} came out 9.13329pt high and 0.0pt deep — exactly the side you asked for and nothing else. That [t] / [b] is not in the LaTeX kernel's \smash; amsmath overwrites the command to add it (the plain, argument-free \smash goes back to plain TeX and is in the LaTeX kernel as well).
% the descender of y drops the middle radical below the other two
$\sqrt{x} + \sqrt{y} + \sqrt{z}$
% smash away only the depth of y, and all three line up
$\sqrt{x} + \sqrt{\smash[b]{y}} + \sqrt{z}$The example amsmath itself gives shows the difference cleanly. In \sqrt{x} + \sqrt{y} + \sqrt{z}, the descender on y makes the middle radical hang slightly lower than the others. In figures, $\sqrt{y}$ is 7.0305pt high and 3.36946pt deep, while $\sqrt{x}$ is 8.00272pt high and 2.39725pt deep. But measure $\sqrt{\smash[b]{y}}$ and you get 8.00272pt high and 2.39725pt deep — identical to $\sqrt{x}$ down to the last decimal. Removing the depth alone returned the radical to exactly the dimensions it has over an x.
Two cautions. First, only the dimensions vanish — the ink stays — so a smashed element can collide with the line above. In body text with tight leading, always look at the result. Second, older write-ups tell you to precede \smash with \leavevmode at the start of a paragraph; that is no longer necessary in the current LaTeX kernel. \finsm@sh in latex.ltx ends with \leavevmode@ifvmode\box\z@, handling vertical mode itself. Using \smash at the head of a paragraph produced no error at all.
Adjacent radicals do not line up at the top — \vphantom and \mathstrut
If \smash brings the tall one down, \vphantom is the opposite operation: it brings the short one up. \vphantom{...} makes a box with the same height and depth as its argument but zero width and nothing printed. Measured, $\vphantom{a^2}$ is 8.14003pt high and 0.0pt wide. Its counterpart $\hphantom{a^2}$ is 0.0pt high and 9.77202pt wide, and $\phantom{a^2}$, which has both, is 8.14003pt high and 9.77202pt wide. The set is neatly complete: vertical only, horizontal only, and both. Put a \vphantom of the taller content into the shorter element and the heights match with nothing visible.
% level the tops of several radicals with one strut each
$\sqrt{\mathstrut a}\;\sqrt{\mathstrut a^2}\;\sqrt{\mathstrut b}$
% or match a specific height by passing the taller content
$\sqrt{a} \;\sqrt{\vphantom{a^2}\,a}$When writing out the target content every time gets tedious, there is an argument-free shortcut, \mathstrut. Its definition in plain TeX reads: \def\mathstrut{\vphantom(}. It is nothing but an invisible opening parenthesis. In mathematics a parenthesis is conveniently tall and follows the font size, which makes it a good yardstick for levelling heights. The measurements agree. $($ is 7.5pt high and 2.5pt deep. $a$ is 4.30554pt high and 0.0pt deep, but $\mathstrut a$ becomes 7.5pt high and 2.5pt deep — the dimensions of the parenthesis exactly — while the width stays at 5.28589pt. Drop one at the head of each element and they all level to one parenthesis worth of height.
Lining up the = signs in align — \phantom and \MoveEqLeft
Pass the very expression you are aligning to into \phantom. When you write out a chain of manipulations, you want the second line onward to drop the left-hand side and start at the =; but pushing it across with plain spaces breaks the moment the font or the formula changes. Write \phantom{f(x)} and you get a blank exactly as wide as f(x) actually set, so the = signs line up on their own. Unlike a hand-counted row of \quad, the width of the blank changes with its contents.
\begin{align*}
f(x) &= x^2 + 2x + 1 \\
\phantom{f(x)} &= (x + 1)^2
\end{align*}
% mathtools: when the first line is too long to keep on one row
\begin{align*}
\MoveEqLeft f(x, y, z) = a + b \\
&= c + d
\end{align*}Conversely, when the left-hand side of the first line is too long to fit before the =, mathtools' \MoveEqLeft helps. It pushes the first line out to the left of the alignment point and sets up the column so later lines fall naturally beneath it. Put it at the head of the line and you never have to count & yourself. The general mechanics of \phantom and \hphantom, and math spacing as a whole, are covered in detail on the “Scripts & spacing” page.
Placing something without letting it take width — \rlap, \llap, \mathclap
This group is the horizontal counterpart of \smash. \rlap{...} prints its contents while giving the box zero width, so the material overhangs to the right. The plain TeX definition is a single line — \def\rlap#1{\hbox to\z@{#1\hss}} — “make a box of width zero and let infinitely stretchable glue push the surplus out to the right”, and nothing more. Measured, \rlap{XX} is 0.0pt wide while a bare XX is 15.00003pt. \llap, which overhangs left, simply puts the \hss first. These are used for notes that spill out of a table column and for pushing line numbers outside the type area.
To do the same inside mathematics, use mathtools' \mathclap (overhangs symmetrically), \mathllap (to the left) and \mathrlap (to the right). The classic case is a long condition under a summation: wrap it as \sum_{\mathclap{1 \le i \le j \le n}} a_{ij} and the width of the formula returns to that of the operator. This group, along with \smashoperator and the text-mode \clap, is covered in detail on the mathtools page. And when you would rather stack the conditions on several lines than squeeze them horizontally, amsmath's \substack{...} is the right answer: write \sum_{\substack{0<i<m \\ 0<j<n}} and the two conditions are set as two lines beneath the summation sign, separated by \\.
Words inside mathematics — \text vs \mathrm vs \operatorname
The three differ on exactly two points: whether the surrounding font is inherited, and whether operator spacing is added. Font first. \text (defined by amstext, which amsmath loads) inherits the surrounding text font, whereas \mathrm always forces upright roman. The measurements make this vivid. Inside \textit{...}, \text{ab} measures 14.24867pt while \mathrm{ab} measures 14.61809pt. Inside \textbf{...}, \text{ab} measures 15.64928pt while \mathrm{ab} measures 14.61809pt again — \mathrm came out identical to the last digit regardless of context. Use \text for words meant to read in the same voice as the surrounding prose, and \mathrm for units and subscript labels that must always be upright.
The second point, spacing, is what separates \mathrm from \operatorname. \operatorname (defined by amsopn, which amsmath loads) treats its contents as an operator, a \mathop, so a breath of space appears automatically on either side. Measured, $\mathrm{max} x$ is 24.32645pt and $\operatorname{max} x$ is 25.99307pt — a difference of 1.66662pt, exactly one 3mu thin space. With an operand on both sides, $a \mathrm{mod} b$ and $a \operatorname{mod} b$ give 28.74428pt against 32.07753pt, a difference of 3.33325pt, that is 6mu (3mu on each side). Curiously, when a ( follows, $\mathrm{max}(x)$ and $\operatorname{max}(x)$ both measured 32.10425pt, exactly the same — because TeX's rules insert no space between an operator and an opening bracket. So concluding “they are the same” from a parenthesised example alone would be premature. When you want the limit set below the symbol, use the starred \operatorname*{max}_{x} (measured 18.61118pt, against 23.6459pt for the unstarred form, which sets the script beside it).
\[
x_{\text{total}} \quad x_{\mathrm{total}}
\qquad
a \operatorname{mod} b \quad a \mathrm{mod} b
\]
% define it once in the preamble instead of repeating \operatorname
\DeclareMathOperator{\rank}{rank}
\DeclareMathOperator*{\argmax}{arg\,max}If the same operator appears repeatedly, defining it once in the preamble is safer than typing \operatorname every time. amsmath's \DeclareMathOperator{\rank}{rank} creates \rank as an operator, and the starred \DeclareMathOperator*{\argmax}{arg\,max} creates the version that puts limits below. With the name and its spelling gathered in one place, changing the notation later is a one-line edit.
Moving things up and down, and pulling them closer — \raisebox and \!
\raisebox{amount}{contents} lifts its contents by the amount you give (pass a negative value to lower them). Measured, X is 6.83331pt high and \raisebox{2pt}{X} is 8.83331pt high — exactly 2pt higher. Give it two further optional arguments, \raisebox{amount}[height][depth]{contents}, and you can override the height and depth it declares to its surroundings. \raisebox{2pt}[0pt][0pt]{X} measured 0.0pt high and 0.0pt deep — moved, and then reduced to the same “zero size” as \smash, in one stroke. It earns its keep when a symbol's position needs the slightest correction, or when swapping a font has thrown something off vertically.
Last, the case where symbols sit too far apart. The negative thin space \! is defined in plain TeX as \def\!{\mskip-\thinmuskip}, making it the exact inverse of \, (3mu), namely −3mu. Measured, $ab$ is 9.57755pt, $a\,b$ is 11.24417pt (+1.66662pt) and $a\!b$ is 7.91092pt (−1.66663pt) — cleanly symmetric. The classic occasion is a multiple integral: $\int\int$ measures 14.99997pt, so open that it reads as two separate integrals. Slip in two \! and $\int\!\!\int$ measures 11.66672pt. And amsmath's dedicated $\iint$ measures 11.66672pt as well — identical to the last decimal. The old-fashioned \int\!\!\int produces a result indistinguishable from the purpose-built command. Even so, where \iint and \iiint exist they state the intent more clearly and read better; think of \! as the tool for situations with no ready-made command.
\[
\int\int f \, dA
\qquad
\int\!\!\int f \, dA
\qquad
\iint f \, dA
\]
% an arbitrary symbol set squarely above another
\[
a \overset{!}{=} b, \qquad x \overset{?}{=} y,
\qquad A \overset{f}{\longrightarrow} B
\]One last item: putting a symbol squarely above an =. Scripts written with ^ and _ attach to the upper right and lower right of a symbol, never directly above or below it. amsmath's \overset{above}{base} and \underset{below}{base} take that role, and \overset{!}{=} is the conventional way to write “this ought to be equal”, \overset{?}{=} “is this equal?”. The second argument is the base; the first is what you add. The fuller uses — applying them to arrows, nesting them — are covered on the “Over/under decorations” page.