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.

For some reason space is added after my equation when I colour it. This does not happen if the colour is added to text.

Is there a simple way to prevent this from happening, like a global setting (I am not interested in manually adjusting the space with \vspace{-1cm})? Perhaps there is a better way to colour my equation (another package, another command, etc), or in other words, am I doing something wrong?

enter image description here

\documentclass[12pt]{standalone}

\usepackage{amsmath}
\usepackage{color}

\begin{document}

\begin{minipage}{4cm}
\begin{equation*}
    a = b + c
\end{equation*}
\begin{align*}
    a - b &= c\\
    a-c & b
\end{align*}
\end{minipage}

\vline

\begin{minipage}{4cm}
\begin{equation*}
\color{blue}    a = b + c
\end{equation*}
\begin{align*}
    a - b &= c\\
    a-c & b
\end{align*}
\end{minipage}

\end{document}

For reference, the closest question I found to this one doesn't seem to solve my problem, ie, adding \fboxsep0pt to my preamble did not change the output.

EDIT Kurt's comment solves part of the problem, but it doesn't work when using for example align (it gives an error):

\begin{align*}
{\color{blue}    a - b &= c}\\
    a-c &= b
\end{align*}

If I try to fix this using the command twice leaving the & outside, the spacing around = is wrong:

\begin{align*}
{\color{blue}    a - b} &{\color{blue}= c}\\
    a-c &= b
\end{align*}
share|improve this question
1  
With {\color{blue}a = b + c} there is no additional space ... –  Kurt Jan 13 '13 at 3:40
1  
Spacing can be fixed via {\color{blue}{}= c}. –  Peter Grill Jan 13 '13 at 3:59
2  
I'm not convinced this has anything to do with color. Two math environments should not be placed 'back to back' like this- you should use gather*. When you use gather*, the spacing is the same in both –  cmhughes Jan 13 '13 at 4:45
2  
@Vivi I won't vote to close this one yet. I think this one merits a definite answer since this deals with a more specific setting. Eventually though, it might get closed. Answering this in the linked post is not within context, I think. Although it was mentioned there that one needs to scope the effect of \color inside {} . –  hpesoj626 Jan 13 '13 at 5:43
2  
@cmhughes: You shouldn't use align* as the inner environment; I didn't even know that this is possible. With aligned as the inner environment, everything works nicely, Vivi. –  Hendrik Vogt Jan 13 '13 at 8:39

1 Answer 1

up vote 12 down vote accepted

Oh. It's an AMS bug, the alignment is not color safe . Never noticed that before:-) In that case you need explicit grouping (use begingroup rather than bgroup or { as it's rather less intrusive into math spacing)

enter image description here

\documentclass[12pt]{standalone}

\usepackage{amsmath}
\usepackage{color}

\begin{document}

\begin{minipage}{4cm}
\begin{equation*}
    a = b + c
\end{equation*}
\begin{align*}
    a - b &= c\\
    a-c & b
\end{align*}
\end{minipage}

\vline

\begin{minipage}{4cm}
\begin{equation*}
\begingroup\color{blue}    a = b + c\endgroup
\end{equation*}
\begin{align*}
    a - b &= c\\
    a-c & b
\end{align*}
\end{minipage}

\end{document}

It's actually a bit harsh to call it an AMS bug, the same effect is seen with \[ in LaTeX however rather than grouping each case, this is probably the correct fix (anywhere in the preamble after loading amsmath. I'll ping @barbarabeeton

\def\foo#1$$#2!!{\def\mathdisplay##1{#1$$\begingroup#2}}
\expandafter\foo\mathdisplay{#1}!!

\long\def\foo#1$$#2!!{\def\endmathdisplay##1{#1\endgroup$$#2}}
\expandafter\foo\endmathdisplay{#1}!!
share|improve this answer

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.