LaTeX \phantom, \vphantom, and \hphantom Commands

May. 18, 2025 • Updated May. 23, 2025

\phantom command

\phantom{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.1

Example 11

1
2
3
4
5
6
7
8
9
\documentclass{article}

\begin{document}

\begin{displaymath}
\int x^2\,dx=\mbox{\underline{$\phantom{(1/3)x^3+C}$}}
\end{displaymath}

\end{document}

image-20250519132114621

Example 2

1
2
3
4
5
6
7
8
9
\documentclass{article}

\begin{document}

\noindent
Thequickbrownfoxjumpsoverthelazydog\\
Thequick\phantom{brownfox}jumps\phantom{over}thelazydog.

\end{document}

image-20250519132159079

Example 32

1
2
3
4
5
6
7
8
9
10
11
12
\documentclass{article}
\usepackage{amsmath}

\begin{document}

\begin{align}
&\mathrel{\phantom{=}} (a+b)(a^2-ab+b^2) \notag \\
&= a^3 - a^2b + ab^2 + a^2b - ab^2 + b^2 \notag \\
&= a^3 + b^3 
\end{align}

\end{document}

image-20250519133020002

Example 42

1
2
3
4
5
6
7
8
\documentclass{article}
\usepackage{amsmath}

\begin{document}

$A_m^n$, $A_m{}^n$ or $A_m^{\phantom{m}n}$ 

\end{document}

image-20250519133344633

Example 53

1
2
3
4
5
6
7
8
9
10
11
12
13
14
\documentclass{article}
\usepackage{amsmath}

\begin{document}

\begin{equation}
\Gamma^{\phantom{i}j}_{i\phantom{j}k},\ 
\begin{bmatrix}
1 & -1\\
2 & \phantom{-}3\\
\end{bmatrix}
\end{equation}

\end{document}

image-20250519134610207


\vphantom command

\vphantom{subformula}: The \vphantom variant produces an invisible box with the same vertical size as subformula, the same height and depth, but having zero width.1

Example 12

1
2
3
4
5
6
7
8
9
10
\documentclass{article}
\usepackage{amsmath}

\begin{document}

\begin{equation}
\sqrt{\frac 12} < \sqrt{\vphantom{\frac12}2},\quad
\sqrt{\frac 12} < \sqrt{2}
\end{equation}
\end{document}

image-20250519132808266

Example 21

1
2
3
4
5
6
7
8
9
10
\documentclass{article}

\begin{document}

\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}

\end{document}

image-20250519133759341

Example 34

1
2
3
4
5
6
7
8
9
10
11
12
13
14
\documentclass{article}
\usepackage{amsmath}

\begin{document}

\begin{equation}
\sqrt{\sum_{0\leq k< n} f(k)}
\sqrt{\vphantom{\sum}\smash{\sum_{0\leq k< n}} f(k)}
\quad\text{vs.}\quad
\sqrt{\sum_{0\leq k< n} f(k)}
\sqrt{\sum\sum_{0\leq k< n} f(k)}
\end{equation}

\end{document}

image-20250519134214592


\hphantom command

\hphantom{subformula}: \hphantom makes a box with the same width as subformula but with zero height and depth.1

Example 1

1
2
3
4
5
6
7
8
9
\documentclass{article}

\begin{document}

\noindent
Thequickbrownfoxjumpsoverthelazydog\\
Thequick\hphantom{brownfox}jumps\hphantom{over}thelazydog.

\end{document}

image-20250519133515112


References