\phantom
& \vphantom
& \hphantom
¶Synopsis:
\phantom{subformula}
or
\vphantom{subformula}
or
\hphantom{subformula}
The \phantom
command creates a box with the same height, depth,
and width as subformula, but empty. That is, this command causes
LaTeX to typeset the space but not fill it with the material. Here
LaTeX will put a blank line that is the correct width for the answer,
but will not show that answer.
\begin{displaymath} \int x^2\,dx=\mbox{\underline{$\phantom{(1/3)x^3+C}$}} \end{displaymath}
The \vphantom
variant produces an invisible box with the same
vertical size as subformula, the same height and depth, but having
zero width. And \hphantom
makes a box with the same width as
subformula but with zero height and depth.
In this example, the tower of exponents in the second summand expression
is so tall that TeX places this expression further down than its
default. Without adjustment, the two summand expressions would be at
different levels. The \vphantom
in the first expression tells
TeX to leave as much vertical room as it does for the tower, so the
two expressions come out at the same level.
\begin{displaymath} \sum_{j\in\{0,\ldots\, 10\}\vphantom{3^{3^{3^j}}}} \sum_{i\in\{0,\ldots\, 3^{3^{3^j}}\}} i\cdot j \end{displaymath}
These commands are often used in conjunction with \smash
.
See \smash
, which includes another example of \vphantom
.
The three phantom commands appear often but note that LaTeX provides
a suite of other commands to work with box sizes that may be more
convenient, including \makebox
(see \mbox
& \makebox
) as well
as \settodepth
(see \settodepth
), \settoheight
(see \settoheight
), and \settowidth
(see \settowidth
).
In addition, the mathtools
package has many commands that offer
fine-grained control over spacing.
All three commands produce an ordinary box, without any special
mathematics status. So to do something like attaching a superscript you
should give it such a status, for example with the \operatorname
command from the package amsmath
.
While most often used in mathematics, these three can appear in other
contexts. However, they don’t cause LaTeX to change into horizontal
mode. So if one of these starts a paragraph then you should prefix it
with \leavevmode
.