# Colored sub and super-scripts are misaligned

The title basically describes the problem. Here is a minimal example:

\documentclass{article}
\usepackage{xcolor}

\begin{document}
$$X_{\color{red}{135}}^{\color{cyan}{345}}$$
\end{document}


When I compile this, the 135 is down and to the left of the 345, rather than directly below it. I get the same issue when I use color instead of xcolor. Any fixes?

-

Using \textcolor{<color>}{<text>} works. Despite the name \text... it actually doesn't change to text mode so the content is still typeset as math.

\documentclass{article}
\usepackage{xcolor}

\begin{document}
$X_{\textcolor{red}{135}}^{\textcolor{cyan}{345}}$
\end{document}


Note that \color doesn't take a second argument. The {135} or {345} behind it is just taken as following material. You should also not use $$ in LaTeX documents. See Why is $...$ preferable to$$?.

-
Thanks! Plus some more characters. –  David Speyer Apr 21 '11 at 22:28

A workaround: use another pair of braces

  $X_{{\color{red}{135}}}^{{\color{cyan}{345}}}$


It probably is some sort of grouping issue.

-
Good point. The { } around the numbers however aren't necessary.. They are not read as argument. –  Martin Scharrer Apr 21 '11 at 22:30
I just had a look at the definition of xcolors definition of \textcolor and all what it does is basically call \leavevmode{\color{<color>}<text>}, so our two answers are leading to the same :-) –  Martin Scharrer Apr 21 '11 at 22:36