I want to make a part of an equation to appear in the center of a (horizontal) phantom. This would be awesome for example for making bra-kets that are all of the same width and still look natural. This is what I want the result to look like:
.
I know how to write right- and left-aligned text inside a phantom:
\usepackage{mathtools}
\begin{gather*}
1 + \mathrlap{B}\phantom{ABC} + 2 \\
1 + \phantom{ABC}\mathllap{B} + 2 \\
1 + ABC + 2
\end{gather*}
I've tried this macro to make a centered text, but it didn't work:
\usepackage{mathtools}
\usepackage{calc}
\newcommand{\hmask}[2]{
\parbox{\widthof{#1}/2}{}
\mathclap{#2}
\parbox{\widthof{#1}/2}{}
}
\newcommand{\mask}[2]{\vphantom{#1}\hmask{#1}{#2}}
\mathclap
should be in math mode.\mathclap
definitely works in math mode, but it makes a zero-width box with its contents centered on the box. But actually positioning the box to the center of the phantom – that's the hard part.