Is it possible to modify the horizontal alignment of the sub and superscript of a symbol? That is to say, is it possible to get this pair of right-aligned sub/superscripts


instead of this left-aligned pair of sub/superscripts


when I have code like this:




Note: I am not looking for a manual solution (e.g. using hphantom which I used to create the above example) but a real automated one-shot-hits-all solution.

Edit: I'm fine with a solution that does not patch the existing sub/superscript mechanism (although I am curious as to whether that is possible). The solution could also employ a custom comman, i.e. \foo{x}{101}{1} as long as it adheres to the proper mathmode sub/superscript spacing etc.

  • tricky with that syntax (or at least tricky not to break everything else) with a syntax \foo{x}{101}{1} it would be easy to measure the two scripts and pad the shorter one automatically. Commented Feb 5, 2016 at 13:49
  • 1
    @DavidCarlisle Alright, maybe I was a bit too strict in my problem description. I'm fine with using a custom function rather than the normal sub/superscript syntax as long as the solution is automated otherwise and uses the correct mathmode sub/superscript spacing.
    – elemakil
    Commented Feb 5, 2016 at 14:03

3 Answers 3


I'm not sure what's the purpose of this, but here it is:



  \ifdim\wd\tw@>\wd\z@ \dimen@=\wd\tw@\fi
  {\mkern0mu \@firstofthree#2}%





enter image description here

Just measure the subscript and superscript and make boxes as wide as the larger one. Note that this works also for second level sub/superscripts.

  • I think I understand how this works. But, I am curious about why you've added \mkern0mu. Is there a particular reason for this?
    – A.Ellett
    Commented Feb 5, 2016 at 14:50
  • @A.Ellett See the comments to wipet's answer
    – egreg
    Commented Feb 5, 2016 at 14:50
  • I see the misalignment, but how does placing the \mkern0mu correct this?
    – A.Ellett
    Commented Feb 5, 2016 at 14:52
  • 1
    @wipet Uh! And what about a hypothetical \subsup{\max}{11}{2}? You surely know where the problem would be. In the example above, ${{}\max}_{1}^2$ would have an unwanted thin space. With \mkern0mu this doesn't happen, of course.
    – egreg
    Commented Feb 5, 2016 at 15:02
  • 1
    @wipet Four braces yours; four tokens mine. This is getting silly.
    – egreg
    Commented Feb 5, 2016 at 16:38

Here's a start, with \Ss{}{}{}. EDITED to work with displaystyle stuff, too. EDITED to automatically work with subscripting styles, as well. FIXED obvious bug that macro did not behave properly if superscript length exceeded subscript length.

\parskip 4pt\centering



enter image description here


For example, you can try this:

  \ifdim\wd2>\wd1 \dimen0=\wd2 \else \dimen0=\wd1 \fi
  \setbox2=\hbox to\dimen0{\hss\box2}%
  \setbox1=\hbox to\dimen0{\hss\box1}%

$\sf x_{100}^{2}$

  • 1
    Not really: try $\sf y_{1}^{200}$
    – egreg
    Commented Feb 5, 2016 at 14:34
  • @egreg It works. Maybe, you have a bad computer.
    – wipet
    Commented Feb 5, 2016 at 14:37
  • 1
    My computer is good and you're wrong: check the picture where the misalignment is very evident. You surely know where the problem is.
    – egreg
    Commented Feb 5, 2016 at 14:40
  • I meant that this is desired feature: to apply the slant property of nucleus to the aligning of subscripts. But if no, then user can use, of course {{}#1}_{\box1}^{\box2}.
    – wipet
    Commented Feb 5, 2016 at 14:46

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .