Most of the time LaTeX sets a formula beautifully, just as you wrote it. Now and then, though, a small blemish remains: a root inside a fraction is so tall it spreads the lines apart, two adjacent square roots fail to line up at the top, a long condition under a sum opens up space on either side. For these last-mile fixes there is a kit of small, sharp tools. This page gathers them as problem → fix. The deep treatment lives on each dedicated page; the aim here is a quick lookup — which command to reach for, for which glitch — with the one tool the other pages do not cover, **\smash**, taking center stage.
The fine-tuning toolkit
One idea runs through all of them: manipulate the dimensions an element occupies (its height, depth, and width) independently of how it looks. If you can make visible ink count as “zero size,” or conversely reserve space for something invisible, you control exactly how a piece affects its neighbours and the line spacing. The vertical extent (height and depth) is governed by \smash, \vphantom, and \mathstrut; the horizontal extent (width) by \mathrlap, \mathllap, \mathclap, and the negative space \!; and both at once by \phantom.
Every one of them is a last touch for fine-tuning the printed result; none changes the meaning of the formula. So the rule of thumb is to write the math plainly first and apply these only where a blemish actually appears. The table below is a quick reference.
| Symptom | Reach for | From | |
|---|---|---|---|
tall-pushes-lines | A tall element spreads the lines apart | \smash (\smash[t] / \smash[b]) | Core LaTeX ([tb] via amsmath) |
radical-heights-differ | Adjacent radicals/rows differ in height | \vphantom / \mathstrut | Core LaTeX |
reserve-space | Reserve room for invisible material to align | \phantom / \hphantom / \vphantom | Core LaTeX |
wide-subscript | A wide subscript widens the column | \mathclap (\mathrlap / \mathllap) | mathtools |
stack-symbol | Stack an arbitrary symbol over =, etc. | \overset / \underset | amsmath |
too-much-space | Symbols sit too far apart | \! (negative thin space) | Core LaTeX |
`\smash` — make height and depth count as zero
Problem. When a root appears in the numerator or denominator of a fraction, the top of \sqrt (the upper edge of the radical sign) rises above a normal line. To keep lines from colliding, LaTeX widens the gap to the line above by just that excess. The upshot is that one line gets extra leading, and the page’s line spacing looks uneven.
Fix. \smash{...} sets its argument as if its height and depth were both zero. The ink (the actual glyphs) still prints, but LaTeX treats the box as having no vertical size, so it no longer decides to widen the leading. The official LaTeX2e reference puts it this way: without \smash, LaTeX “would separate its line from the line above it, and the uneven line spacing might be unsightly” (with the caveat that the smashed material may then run into the line above).
% 問題:分数のなかの根号が、この行だけ行間を押し広げる
$y = \frac{1}{\sqrt{1 - x^2}}$
% 直し方:根号の高さをゼロ扱いにして行送りへの影響を消す
$y = \frac{1}{\smash{\sqrt{1 - x^2}}}$Both render the same formula, but in the second the height of \sqrt{1-x^2} is left out of the leading calculation, so the line is spaced like its neighbours. This matters most when a tall element sits in inline math within running text.
With amsmath loaded, \smash gains an optional argument. \smash[t]{...} smashes only the top (the height), leaving the depth natural, while \smash[b]{...} smashes only the bottom (the depth), keeping the height. As the amsmath manual notes, it is occasionally advantageous to “smash only the top or only the bottom of something while retaining the natural depth or height.”
A representative case from amsmath itself is leveling adjacent square roots. In \sqrt{x} + \sqrt{y} + \sqrt{z}, the letter y has a descender, so the middle radical hangs slightly lower. Smashing away just that depth with \smash[b] brings the three roots into line.
% amsmath マニュアルの例:まんなかの根号だけ下がるのを直す
$\sqrt{x} + \sqrt{y} + \sqrt{z}$ % y の descender で不ぞろい
$\sqrt{x} + \sqrt{\smash[b]{y}} + \sqrt{z}$ % y の深さを消してそろえる\smash works in text as well as in math, but in text it does not enter horizontal mode, so at the very start of a paragraph it needs a preceding \leavevmode. Note that \smash and the next section’s \vphantom are opposite operations: \smash makes something large count as zero, while \vphantom gives something of zero size a real height. Indeed, amsmath shows the two used together to equalize heights.
`\vphantom` and `\mathstrut` — leveling with invisible height
Problem. The mirror image of \smash: sometimes you want to raise the shorter element to match the taller one. Set \sqrt{a} beside \sqrt{a^2} and the exponent makes the right radical taller, so their tops do not align. The same happens in cases or matrices when rows differ in height.
Fix. \vphantom{...} (vertical phantom) makes an invisible box with the same height and depth as its argument but zero width. Put a \vphantom of the taller content into the shorter element and the heights match while nothing shows. The argument-free shortcut is \mathstrut (“math strut”), defined as \vphantom( — an invisible strut one open-parenthesis tall. Drop it at the head of each element and they level to one parenthesis’ worth of height.
% 根号の天井をそろえる:各 \sqrt の中身に \mathstrut を足す
$\sqrt{\mathstrut a}\;\sqrt{\mathstrut a^2}\;\sqrt{\mathstrut b}$
% 任意の高さにそろえたいときは、揃え先の中身を \vphantom に渡す
$\sqrt{a} \;\sqrt{\vphantom{a^2}\,a}$These are covered in detail on the Scripts & spacing page, so see there for the mechanics and how \hphantom differs. The point to take away here: **\smash (bring the tall one down) and \vphantom / \mathstrut (bring the short one up) are two sides of the same coin** for matching heights.
`\phantom` — aligning by reserving invisible space
Problem. Across several lines, you want this term on the lower line to sit directly under that term on the upper line, but the differing lengths on the left throw the columns off. Padding with manual spaces breaks again whenever the font or formula changes.
Fix. \phantom{...} is an invisible box with the same height, depth, and width as its argument set normally. Pass the very expression you are aligning to into \phantom, and you get a blank exactly as wide as that expression, so the columns line up naturally. When you want only the width, use \hphantom{...} (zero height and depth).
% 「= 」の左を、上の行の項の幅だけ空けて桁をそろえる
\begin{align*}
f(x) &= x^2 + 2x + 1 \\
\phantom{f(x)} &= (x + 1)^2
\end{align*}Here \phantom{f(x)} on the left of the second line reserves a blank as wide as f(x), so the two = signs align vertically. The full \phantom family (\hphantom, \vphantom) is also detailed on the Scripts & spacing page.
`\mathclap`, `\mathrlap`, `\mathllap` — zero-width boxes (the horizontal `\smash`)
Problem. The condition placed under a sum or product is sometimes wider than the operator itself — say \sum_{1 \le i \le j \le n}. LaTeX then opens space on both sides of the summation sign to fit that width, and the whole formula looks stretched. Inside tables or alignments, that extra width can knock a whole column out of line.
Fix. mathtools’ \mathclap{...} puts its argument in a zero-width box and centers it (protruding equally on both sides). The condition stays visible while the formula’s width is held to that of the operator itself. To protrude on one side only, use \mathllap{...} (toward the left) or \mathrlap{...} (toward the right). These were in fact created as the **horizontal counterpart of \smash**: where \smash zeroes the vertical size, the lap commands zero the horizontal size (the width).
% 問題:長い下付き条件が総和の前後に余白を作る
\[ \sum_{1 \le i \le j \le n} a_{ij} \]
% 直し方:条件を幅ゼロの箱に入れ、式の幅を記号本体に保つ
\[ \sum_{\mathclap{1 \le i \le j \le n}} a_{ij} \]This assumes mathtools is loaded (\usepackage{mathtools}, which pulls in amsmath automatically). These commands, the text-mode \clap, and the optional [mathstyle] argument are covered in detail on the mathtools page.
Stacking symbols, and pulling things closer
Problem (one). You sometimes want to set an arbitrary small symbol directly above or below an existing one — an exclamation mark over an equals sign for “equal by requirement,” \overset{!}{=}, or \overset{?}{=} for “is this equal?”. Scripts (^, _) attach at the right side of a symbol, not squarely above or below it.
Fix. Use amsmath’s \overset{above}{base} and \underset{below}{base}. \overset{!}{=} sets a small exclamation mark right above the equals sign. The second argument is the base; the first is what you add.
\[
a \overset{!}{=} b, \qquad x \overset{?}{=} y,
\qquad A \overset{f}{\longrightarrow} B
\]The fuller use of \overset / \underset (applying them to arrows, nesting them) is on the Over/under decorations page.
Problem (two). Conversely, symbols can sit too far apart. The classic case is a double or triple integral: \int\int leaves so much room between the signs that they read as separate integrals.
Fix. Pull them together with the negative thin space \! (−3 mu, the exact inverse of \,). Inserting it as \int\!\!\int brings the two integral signs to a sensible distance (amsmath also offers dedicated \iint and \iiint for multiple integrals). The full set of math spacing nudges that includes \! is tabulated on the Scripts & spacing page.
\[
\int\int f \, dA % 間が空きすぎ
\qquad
\int\!\!\int f \, dA % \! で適度に詰める
\]