8

As part of a document, I am typesetting the objects q_x^{n_x} and q_y^{n_y} right next to each other, as

\frac{ q_x^{n_x} q_y^{n_y} }{2}

It bugs me that the n_y gets displayed at a different baseline than the n_x, though I understand the core reason for it (i.e. probably due to the taller subscript in q_y).

Is there a way to enforce consistency in the typesetting of this combination?

  • @campa No, that's probably enough. I'd be interested to know why it works, but I'm happy with that. – E.P. Mar 10 '16 at 13:18
10

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

  • I'm blushing... :-) – Mico Mar 10 '16 at 13:37
  • 1
    @Mico Been there, done that! ;-) – egreg Mar 10 '16 at 13:44
  • Can you comment on the relationship between these solutions and the \displaystyle solution proposed in the comments? – E.P. Mar 10 '16 at 17:54
  • @E.P. I don't consider \displaystyle a solution; it's just by chance that, in this case, it gives the same result as with the “double \vphantom” trick. – egreg Mar 11 '16 at 20:43
5

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}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.