[Tex/LaTex] position of the slash in hatted \slashed

positioningstacking-symbolssymbols

So I want to denote the Dirac operator with a hat, and I tried both \hat{\slashed{D}} and \slashed{\hat{D}}: the first one has the $^$ rather distant to the $\slashed{D}$, while the second one has the slash much too to the left of the $D$, almost coincide the semi-vertical stroke of the letter $D$.

Is there any way to adjust the position of the hat or slash?

Best Answer

Just overlap the symbol with the hat with the slashed version of itself.

\documentclass{standalone}
\usepackage{mathtools,slashed}
\newcommand\hatslashed[1]{{\hat{#1}\mathllap{\slashed{#1}}}}
\begin{document}
$\hat{\slashed{D}}$
$\slashed{\hat{D}}$
$\hatslashed{D}_{\hatslashed{D}_{\hatslashed{D}}}$
\end{document}

enter image description here


You can use \phantom in the following way to prevent double striking the glyph, but AFAIK \phantom doesn't detect cramped style and shifts the hat to the right.

\newcommand\hatslashed[1]{{\hat{\phantom{#1}}\mathllap{\slashed{#1}}}}
Related Question