Inconsistent superscript placement in $q_x^{n_x} q_y^{n_y}$

Aligning subscripts and superscripts requires some thought and examination of the relative shapes: the combinations are really too many for being able to devise an automatic solution.

In your case there are no descenders in the subscripts to the first “q”, but there are two in the second case. However the subscript “y” in the superscript doesn't really need space below it, because it sticks clear of the main subscript. So this case calls for “smashing the descender”:

In the following example, the first line is au naturel, the second line implements Mico's excellent suggestion, the third one improves on it. In the fourth line the two solutions are side-by-side for better comparing them.

\documentclass{article}
\usepackage{amsmath}
\newcommand{\vy}{\vphantom{y}} % vertical phantom with height and depth of "y" glyph
\begin{document}

\begin{gather*}
\frac{ q_x^{n_x} q_y^{n_y} }{2} \\
\frac{ q_{x\vy}^{n_{x\vy}} q_y^{n_y} }{2} \\
\frac{ q_{x\vy}^{n_{x}} q_y^{n_{\smash[b]{y}}} }{2} \\[\medskipamount]
\frac{ q_{x\vy}^{n_{x\vy}} q_y^{n_y} }{2}
\frac{ q_{x\vy}^{n_{x}} q_y^{n_{\smash[b]{y}}} }{2}
\end{gather*}

\end{document}

enter image description here


You can use a "vertical phantom" -- specifically, an invisible object that has the height and depth of the glyph "y" -- to adjust the positions of the two "x" characters in the first subformula, viz., q_x^{n_x}.

enter image description here

\documentclass{article}
\newcommand{\vy}{\vphantom{y}} % vertical phantom with height and depth of "y" glyph
\begin{document}
$\displaystyle
\frac{ q_x^{n_x} q_y^{n_y} }{2} 
\quad\mbox{vs.}\quad
\frac{ q_{x\vy}^{n_{x\vy}} q_y^{n_y} }{2}
$
\end{document}

Addendum: While the \vphantom method succeeds in placing all sub- and superscripts at mutually consistent heights, one might object that the x and y subscripts to q are positioned "too high". To force these subscripts to be placed a bit lower, then, one can insert \mathstrut directives:

enter image description here

\documentclass{article}
\newcommand{\vy}{\vphantom{y}} % vertical phantom
\begin{document}
$\displaystyle
\frac{ q_x^{n_x} q_y^{n_y} }{2} 
\quad\mbox{vs.}\quad
\frac{ q_{x\mathstrut}^{n_{x\vy}} q_{y\mathstrut}^{n_{y}} }{2}
$
\end{document}