What goes wrong is that the argument of the square root is typeset in a cramped style.
If the radical appears in display style, then the material under the square root sign is typeset in cramped display style. However, \phantom
only chooses among the uncramped styles, so you get a different height. In the following picture you see the output of a^2
in uncramped and cramped styles
![enter image description here](https://cdn.statically.io/img/i.sstatic.net/naq0x.png)
Clearly this explains the difference in placement of the radical sign you get.
Use \cramped
from mathtools
:
\documentclass{article}
\usepackage{mathtools}
\begin{document}
\begin{align}
&\sqrt{a^2b}\,\sqrt{\phantom{\cramped{a^2}}b} \\
&\sqrt{\phantom{\cramped{a^2}}b}\,\sqrt{a^2b} \\
&\sqrt{\frac{1}{2}}
\end{align}
\end{document}
![enter image description here](https://cdn.statically.io/img/i.sstatic.net/z4cEz.png)
If you use LuaLaTeX, then there's a slicker way: redefining \mathpalette
.
\documentclass{article}
\usepackage{amsmath}
\renewcommand*{\mathpalette}[2]{%
\ifcase\mathstyle\relax
#1\displaystyle{#2}\or
#1\crampeddisplaystyle{#2}\or
#1\textstyle{#2}\or
#1\crampedtextstyle{#2}\or
#1\scriptstyle{#2}\or
#1\crampedscriptstyle{#2}\or
#1\scriptscriptstyle{#2}\or
#1\crampedscriptscriptstyle{#2}\fi
}
\begin{document}
\begin{align}
&\sqrt{a^2b}\,\sqrt{\phantom{a^2}b} \\
&\sqrt{\phantom{a^2}b}\,\sqrt{a^2b} \\
&\sqrt{\displaystyle a^2b}\,\sqrt{\displaystyle\phantom{a^2}b}\\
&\sqrt{\displaystyle\phantom{a^2}b}\,\sqrt{\displaystyle a^2b}
\end{align}
\end{document}
![enter image description here](https://cdn.statically.io/img/i.sstatic.net/FgymL.png)
Caveat The above redefinition of \mathpalette
doesn't guarantee success in all cases, particularly when a command defined with \mathpalette
is used in a fraction. It's essentially a proof of concept.