Fractions in superscripts are placed too low

I have noticed that "tall" superscripts seem to be placed awkwardly low in math mode; their baseline is so close to the main baseline that confusion has happened.

\documentclass{article}
\begin{document}\centering
$$2^{\left\lfloor\frac{1}{2}\right\rfloor} \quad 2^a \quad 2^{\left\lfloor\frac{1}{2}\right\rfloor}_{\phantom{i}}$$
$2^{\left\lfloor\frac{1}{2}\right\rfloor} \quad 2^a \quad 2^{\left\lfloor\frac{1}{2}\right\rfloor}_{\phantom{i}}$
\end{document}


With texlive 2012, this code compiles to this:

There does not seem to be a significant difference between text and display mode. Including a phantom subscript raises the exponent up to (roughly?) the usual baseline; this is fine for the purpose of clarity, but I'll admit it looks kind of awkward. Also, treating all instances thus is not feasible.

How can I ensure that "tall" superscripts are clearly identifiable as such?

-
Related questions: Position of Exponent Relative to Base -- similar problem, but concerned with the other boundary, and apparently unresolved. Fraction in Superscript -- similar problem but text mode, and accepted solution is "only" a local hack. –  Raphael Oct 24 '12 at 11:47

2 Answers

See appendix G of the TeXbook for full details about the font parameters of the symbol font control script positions.

\documentclass{article}

\begin{document}\centering

$$2^{\left\lfloor\frac{1}{2}\right\rfloor} \quad 2^a \quad 2^{\left\lfloor\frac{1}{2}\right\rfloor}_{\phantom{i}}$$
$2^{\left\lfloor\frac{1}{2}\right\rfloor} \quad 2^a \quad 2^{\left\lfloor\frac{1}{2}\right\rfloor}_{\phantom{i}}$

\setbox0\vbox{\hbox{$$}$$ }
\fontdimen13\textfont2 = 10pt
\fontdimen14\textfont2 = 7pt
$$2^{\left\lfloor\frac{1}{2}\right\rfloor} \quad 2^a \quad 2^{\left\lfloor\frac{1}{2}\right\rfloor}_{\phantom{i}}$$
$2^{\left\lfloor\frac{1}{2}\right\rfloor} \quad 2^a \quad 2^{\left\lfloor\frac{1}{2}\right\rfloor}_{\phantom{i}}$
\end{document}


If you don't want to mess with fontdimens (which isn't as bad as it seems, although I was using extreme values to highlight the effect) you could move the subscript so it has no depth which will change TeX's positioning logic for example

\def\bigsup#1{^{\vbox{\hbox{$\scriptstyle#1$}\nointerlineskip\hbox{}}}}

$$2\bigsup{\left\lfloor\frac{1}{2}\right\rfloor}$$


produces

-
This seems to be quite a sledgehammer. Is there a way to restrict your solution to "tall" superscripts? (I prefer the way displaymath looks for smaller \fontdimen13, say 7 or 8.) –  Raphael Oct 24 '12 at 12:14
you might note that the font parameter position is relative to the baseline of the script, and the baseline of a fraction is not at the bottom. the upper and lower extents of a fraction will only get looked at if there's a concurrent sub/superscript. (and i'd also take a look to see if a (phantom) subscript x gives a different result than i.) –  barbara beeton Oct 24 '12 at 12:19
@barbarabeeton "the upper and lower extents of a fraction will only get looked at if there's a concurrent sub/superscript" -- does that mean there is no hope short of hacking TeX, because tall superscripts can not be identified as such? (I don't quite get your comment about different baselines.) (x does not change the result in any way I can perceive. The reason for using i was not to skrew up horizontal spacings.) –  Raphael Oct 24 '12 at 13:08
@Raphael -- i think that hacking tex is the only "reasonable" possibility. david should be better able to address this. i've experimented with a few conceivable workarounds, and found nothing that isn't worse than the expedient of adding a dummy subscript. and you're correct that using i doesn't give any different results than x (or X, or even a parenthesis); i was making a wild guess, not having the energy to investigate appendix g. but if you're concerned about width, \vphantom is your friend. –  barbara beeton Oct 24 '12 at 13:51

I use a combination of the \stackrel and \phantom commands. In particular

\newcommand{\rz}[1]{\stackrel{#1}{\phantom{.}}}


seems to work well (i.e. looks pretty natural) in many cases. If you want precise control, I suppose you can replace the \phantom{.} with

\phantom{\begin{minipage}{0.001\textwidth}\vspace{#2}\end{minipage}}


Then the #2 argument will control the precise height to raise the exponent.

For example:

\documentclass{article}
\newcommand{\bla}{\left\lfloor\frac{1}{2}\right\rfloor} %floor(1/2)
\newcommand{\rz}[1]{\stackrel{#1}{\phantom{.}}} %to raise exponents just a bit
\newcommand{\rzp}[2]{\stackrel{#1}{\phantom{\begin{minipage}{0.001\textwidth}\vspace{#2}\end{minipage}}}} %to raise exponents by a precise amount
\begin{document}\centering

$2^{\bla}$ \hspace{.25 in} %do nothing to exponent
$2^{\rz{\bla}}$\hspace{.25 in} %raise exp. by height of '.'
$2^{\rzp{\frac{1}{2}}{0.2 in}}$ %raise exp by height of 0.2 in
\vspace{1 in}

$2^{\frac{1}{2}}$\hspace{.25 in} %do nothing to exponent
$2^{\rz{\frac{1}{2}}}$\hspace{.25 in} %raise exp. by height of '.'
$2^{\rzp{\bla}{0.3 in}}$ %raise exp by height of 0.3 in

\end{document}


will output:

-
I am using this code, but I have a question, if you use $\frac{a^p}{a^{\rz{q}}}$ the size of both exponent are different, the exponent p is bigger than the exponent q, how can I fix this? –  Gitano Jan 21 at 19:41
I forgot to say that I am using \everymath{\displaystyle} in the preambule –  Gitano Jan 21 at 19:43
I can't say I know the cause of this issue, but \newcommand{\rz}[1]{\displaystyle\stackrel{#1}{\phantom{.}}} seems to work for me. All I did was to add \displaystyle before \stackrel. –  AndyP Jan 22 at 20:07
Thanks, it works for me too –  Gitano Jan 22 at 23:01