5

I would like to color a paragraph in blue. As my text contains some equations, I followed the advice given in this answer. However, I get extra vertical space when the paragraph ends with an align environment, as shown below.

\documentclass{article}
\usepackage{amsmath}
\usepackage{xcolor}

\begin{document}
{ \color{blue}This is is a paragraph in blue. It contains the equation
\begin{align*}
a & = b + c - 2c\\
&= b - c.
\end{align*}
}

This is a new paragraph in black.
\end{document}

enter image description here

What is the best approach for coloring a paragraph without creating any extra space?

0

1 Answer 1

5

(At least with PDFLaTeX) \color{…} results in a whatsit and is therefore horizontal material. Unfortunately switching back to the previous color at the end of a group also needs a whatsit. So in your case, there is an extra paragraph after the \end{align*} caused by switching of the color. My suggestion is to avoid the group and explicitly switch to \normalcolor at the beginning of the next paragraph:

\documentclass{article}
\usepackage{amsmath}
\usepackage{xcolor}

\begin{document}

\color{blue}%
This is is a paragraph in blue. It contains the equation
\begin{align*}
  a & = b + c - 2c\\
    &= b - c.
\end{align*}

\normalcolor
This is a new paragraph in black.
\end{document}

no extra paragraph

An alternative would be to use LuaLaTeX and package luacolor:

\documentclass{article}
\usepackage{amsmath}
\usepackage{xcolor}
\usepackage{luacolor}

\begin{document}

{\color{blue}%
  This is is a paragraph in blue. It contains the equation
  \begin{align*}
    a & = b + c - 2c\\
      &= b - c.
  \end{align*}}

This is a new paragraph in black.
\end{document}

With luacolor colors are not longer whatsits (and therefore horizontal material) but node attributes. One more advantage of using LuaLaTeX.

One more alternative would be to add a \par after the end of the align* but before the end of the group, because the color code tries to avoid such issues in vertical mode:

\documentclass{article}
\usepackage{amsmath}
\usepackage{xcolor}

\begin{document}

{\color{blue}%
  This is is a paragraph in blue. It contains the equation
  \begin{align*}
    a & = b + c - 2c\\
      &= b - c.
  \end{align*}\par}

This is a new paragraph in black.
\end{document}

You must log in to answer this question.

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