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.

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?

share|improve this question
add comment

2 Answers

up vote 4 down vote accepted

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 $$?.

share|improve this answer
    
Thanks! Plus some more characters. –  David Speyer Apr 21 '11 at 22:28
add comment

A workaround: use another pair of braces

  \[ X_{{\color{red}{135}}}^{{\color{cyan}{345}}}\]

It probably is some sort of grouping issue.

share|improve this answer
    
Good point. The { } around the numbers however aren't necessary.. They are not read as argument. –  Martin Scharrer Apr 21 '11 at 22:30
3  
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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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