Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Possible Duplicate:
Subscripts for primed variables

If I have a variable which is always subscripted but only sometimes superscripted, the vertical position of the subscript varies. For instance, $s^*_i$ and $s^{}_i$ are different from $s_i$. Can I define the subscript such that it is always in the same position regardless of the presence of a superscript?

share|improve this question

marked as duplicate by Werner, egreg, tohecz, Loop Space, lockstep Apr 13 '12 at 18:47

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

add comment

2 Answers

up vote 12 down vote accepted
\usepackage{subdepth}

Example

\documentclass{article}
\usepackage{subdepth}
\begin{document}
$a_i a_i^2$
\end{document}

enter image description here

share|improve this answer
add comment

I would define a macro to handle this in a consistent way. The following minimal example defines \var[<var>]{<sub>}[<sup>] that sets <var>_{<sub>}^{<sup>} (<var> and <sup> are optional). The addition of an empty <sup> ensures a consistent height for your superscripts. If your optional <sup> is something other than a "normal superscript" (let's call it "bizarre"), adding \vphantom{<bizarre sup>} before #3 should take care of the vertical alignment:

enter image description here

\documentclass{article}
\usepackage{xparse}% http://ctan.org/pkg/xparse
\NewDocumentCommand{\var}{O{s} m O{}}{%
  \ensuremath{#1_{#2}^{#3}}% add \vphantom{<bizarre sup>}
}
\begin{document}
$s_i\ s_i^*$\ \var{i}\ \var{i}[*]\ \var[a]{k}\ \var[a]{k}[*]
\end{document}​

<var> has a default of s. If <sup> contains other (more complex) elements, you could use \mathstrut. That is, with some knowledge of the input, you can optimise the output.

It would also be possible to modify the macro to allow you to use superscript notation ^{..} as needed, rather than an optional <sup> argument, but this enforce the use of math mode, rather than using \ensuremath.

xparse provides the macro definition interface.

share|improve this answer
1  
Actually ^{} is sufficient (no need of \vphantom). And here \ensuremath is very questionable. –  egreg Apr 12 '12 at 17:17
    
@egreg: I've incorporated your first suggestion. :) –  Werner Apr 12 '12 at 17:25
    
Thanks -- elegant but I will keep this in mind as an example of xparse... –  crippledlambda Apr 12 '12 at 18:29
add comment

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