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 box but not its ink. The \vphantom
variant also produces an invisible box with the same height and depth as subformula, but it has width zero. And \hphantom
makes a box with the same width as subformula but with height and depth zero.
Without the \vphantom
in this example, the top bars of the two square roots would be at different heights.
\( \sqrt{\vphantom{a^3}a}\cdot\sqrt{a^3} \)
The \vphantom{a^3}
causes the first \sqrt
to have inside it a box of the same height as the second \sqrt
, so LaTeX makes the bars align.
These commands often are combined with \smash
. See \smash, for another example of the use 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
.
© 2007–2018 Karl Berry
Public Domain Software
http://latexref.xyz/_005cphantom-_0026-_005cvphantom-_0026-_005chphantom.html