I cannot remember how to create an invisible character in LaTeX, i.e. I want to put a space that has the width of a particular character, say `M'. I know there is a command for this, and this is a really dumb question, but my Google-fu has failed me.
Asked
Active
Viewed 3.4e+01k times
317
-
6Could you mark the answer that answers your question best as solution, please? – Golar Ramblar Nov 18 '21 at 22:08
3 Answers
403
You already found the answer, but let me expand a bit. There are three phantom commands. They each take a single argument.
\hphantom(horizontal phantom) inserts an empty box that has zero height, zero depth, but the width of its argument.\vphantom(vertical phantom) inserts an empty box that has the height and depth of the argument, but zero width.\phantominserts an empty box with the same dimensions (horizontal as well as vertical) as the argument.
-
58
-
98Height is the length above the baseline, depth is the length below. So a character such as "X" will have a height but zero depth, and "g" has (a smaller) height as well as depth. – Will Robertson Oct 25 '10 at 03:44
-
9@Kit: You might also want to see the illustration in the question http://tex.stackexchange.com/q/151584/25077 – strpeter May 27 '14 at 15:00
-
2Also Alexander R. Perlis' article in TUGboat, Volume 22 (2001), No. 4, p.350ff., might be of interest (especially the illustrations). – Stephen Jun 26 '15 at 17:07
-
3
-
1Just an additional comment: The phantom commands can lead to some unexpected behavior, which can for example lead to additional blank lines as explained in egreg's answer to this question. – StackJack Apr 17 '18 at 20:12
-
@StackJack That's a great point. It can be useful to use
\leavevmodeor\quitvmodebefore using the various phantom commands when in vertical mode. – TH. Apr 24 '18 at 17:14 -
1It may be useful to mention that in a math environment, the typesetter may wish to write
\mathbin{\phantom{%character%}}in order to mimic the whitespace some operators are padded with in math mode. – Oct 09 '18 at 20:58 -
Also, check this listing of different spacing commands: https://tex.stackexchange.com/a/74354/6468. – Computist Apr 17 '19 at 16:56
-
It seems that
\hphantom{}an be used to create zero-width, non-printing content if TeX insists on having content but you don't want anything there (e.g. a bare\paragraph{Foo}where the next "real" content is unrelated). – BCS Oct 02 '22 at 00:03
78
Ok, this has already been answered so I just want to contribute with the usage of the \phantom command.
\begin{document}
This text will be visible. \\
\phantom{This text will be invisible} \\
\fbox{\phantom{This text will be invisible too, but a box will be printed arround it.}}
\end{document}
Christian Rodriguez
- 1,041
