9

The below snippet, within an equation array environment, gives the subsequent rendering:

F\left[C^{(n-k)}_{P_{ji}}\right]

Without color

But when I add color to the snippet (using the color package) as below (adding line breaks here to facilitate legibility) in the same environment I get the subsequent bit of unpleasantness:

\color[rgb]{0.000,0.000,1.000}F\left[\color[rgb]{0.000,0.750,0.000}C
\color[rgb]{0.000,0.750,0.000}^{(n-k)}\color[rgb]{0.750,0.750,0.000}
_{P_{ji}}\color[rgb]{0.000,0.000,1.000}\right]

With color

I get this whether or not I include the color codes for the super and subscripts prior to the ^ and _ or within the subsequent {}s.

1 Why am I getting this discrepancy?

2 Can I easily correct it in my code using these packages?

3 Is this a bug?

And here is a full document to illustrate:

\documentclass[fleqn,10pt]{article}
\newcommand\independent{\protect\mathpalette{\protect\independenT}{\perp}}
\def\independenT#1#2{\mathrel{\rlap{$#1#2$}\mkern2mu{#1#2}}}
\usepackage{color}
\usepackage{amssymb}
\usepackage{amsmath}
\usepackage[utf8]{inputenc}
\begin{document}
\begin{eqnarray}
F\left[C^{(n-k)}_{P_{ji}}\right]
\end{eqnarray}

\begin{eqnarray}\color[rgb]{0.000,0.000,1.000}F\left[\color[rgb]{0.000,0.750,0.000}C\color[rgb]{0.000,0.750,0.000}^{(n-k)}\color[rgb]{0.750,0.750,0.000}_{P_{ji}}\color[rgb]{0.000,0.000,1.000}\right]\end{eqnarray}

\end{document}

1 Answer 1

12

A \color instruction inserts an empty math formula which makes it impossible for the subscript to be attached to the preceding atom.

Use \mathcolor instead, whenever possible.

\documentclass{article}
\usepackage{xcolor}
\begin{document}

\begin{equation}
F\left[C^{(n-k)}_{P_{ji}}\right]
\end{equation}

\begin{equation}
\color[rgb]{0.000,0.000,1.000}F\left[
\color[rgb]{0.000,0.750,0.000}C
^{\mathcolor[rgb]{0.000,0.750,0.000}{(n-k)}}
_{\mathcolor[rgb]{0.750,0.750,0.000}{P_{ji}}}
\color[rgb]{0.000,0.000,1.000}
\right]
\end{equation}

\end{document}

enter image description here

Never ever use eqnarray: see eqnarray vs align

9
  • @Alexis Penitentiagite! (From Umberto Eco's “The name of the rose”.)
    – egreg
    Commented Jan 5, 2015 at 18:13
  • Seeing and raising you: youtube.com/watch?v=YgYEuJ5u1K0
    – Alexis
    Commented Jan 5, 2015 at 18:16
  • How can I adapt this solution if I want to use \normalcolor?
    – Jakob
    Commented Nov 6, 2023 at 12:12
  • @Jakob Not sure what you mean.
    – egreg
    Commented Nov 6, 2023 at 12:55
  • @egreg: Is there a something like \mathnormalcolor{} or \mathtcolor{normal}{}? (In my case \colorlet{saved}{.} solved my problem even better than \normalcolor I found out in the meantime.)
    – Jakob
    Commented Nov 6, 2023 at 15:28

You must log in to answer this question.

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