# How can I improve alignment of the numerator and denominator when vector norm bars along with subscripts throw things off?

With a red bar to show what is bothering me in particular:

Here's a simpler case where the issue is a non-issue, but perhaps one can get a hint of why it starts to get bad:

Here's some minimum code to produce the problem examples:

\documentclass{article}

\usepackage{amsmath}
\usepackage{physics}

\newcommand{\mycommand}[1]{\ensuremath{{#1}_{p}}}

\renewcommand{\vec}[1]{\ensuremath{\mathbf{#1}}}
\newcommand{\normv}[2][p]{%
\ensuremath{\norm{\vec{#2}}_{#1}}%
}

\begin{document}
\begin{equation*}
0 = \frac{x}{\mycommand{x}}
\end{equation*}

\begin{equation*}
\vec{x} = \frac{\vec{x}}{\normv{x}}
\end{equation*}
\end{document}


I got the following bit of code from the answer to this question:

\newcommand{\alignedvfrac}[2]{%
\setbox0\hbox{$#1$}        % put the numerator in box0
\dimen0=\wd0               % measure box0
\setbox1\hbox{$#2$}        % put the denominator in box1
\dimen1=\wd1               % measure box1
\ifdim\wd0<\wd1            % if box0 is narrower than box1
\dfrac{#1\hfill}{#2}   % put \hfill in the numerator
\else
\dfrac{#1}{#2\hfill}   % otherwise put \hfill in the denominator
\fi
}


Using it does not help:

I don't understand why it doesn't work as it seems that the problems are basically the same. Can you help me understand?

• you could make it symmetric using \hphantom{{}_p} on the left side – MaxNoe May 3 '15 at 21:26
• for the first case (with the double verts), you can use \mathrlap{_p) to make the subscript have "no width". requires mathtools. – barbara beeton May 3 '15 at 21:28
• @barbarabeeton That works beautifully. So if I understand correctly, \mathrlap{_p} basically "hides" the subscript in the calculation for the box size? – user89 May 3 '15 at 21:44
• @barbarabeeton the reason why I ask is because if put double verts around the whole fraction, the double verts overlap on the _p, and there are other such clashes..., so somehow, I need it to go into mathrlap only for the alignment of the numerator and denominator, but then revert back to normal mode – user89 May 3 '15 at 21:51
• I don't think you should be concerned with that nonalignment. There's no reason for the two letters being aligned. – egreg May 4 '15 at 7:35

Here is another solution, which consists in adding a phantom prescript to the norm. As the fraction line might a little wide, acorrection might be necessary (more typing… but part of the correction can be incorporated to the norm command. Also, as I don't have the physics package installed, I defined the norm command with the help of mathtools:

\documentclass{article}

\usepackage{mathtools}
%\usepackage{physics}
\DeclarePairedDelimiter\norm{\lVert}{\rVert}

\newcommand{\mycommand}[1]{\ensuremath{{#1}_{p}}}

\renewcommand{\vec}[1]{\ensuremath{\mathbf{#1}}}

\newcommand{\normv}[2][p]{%
\ensuremath{{}_{\phantom{#1}}\norm{\vec{#2}}_{#1}}%
}

\newcommand{\normw}[2][p]{%
\ensuremath{{}_{\!\phantom{#1}}\norm{\vec{#2}}_{#1}\!}%
}

\begin{document}
\begin{equation*}
0 = \frac{x}{\mycommand{x}}
\end{equation*}

\begin{equation*}
\vec{x} = \frac{\vec{x}}{\normv{x}}
\end{equation*}

\begin{equation*}
\vec{x} = \frac{\!\vec{x}\!}{\normw{x}}
\end{equation*}

\end{document}


• Thanks very much for this answer! What are the \! commands called? – user89 May 4 '15 at 22:46
• It adds a negative thin space (works only in math mode), just as \, adds a thin space.. – Bernard May 4 '15 at 22:55