21

I want to write a document where a paragraph or two has a different text colour. I am using the \textcolor environment for this. But here is the problem

when I write

 \textcolor{red}{blah blah blah} 

everything is fine.

But when I try this

 \textcolor{red}{blah blah 

 % A paragraph here 

 blah blah }

Then the colour disappears.

EDIT: Here is a MWE:

  \documentclass{article}
  \usepackage{color}
  \begin{document}
  \textcolor{red}{blah blah blah}


 However 

 \textcolor{red}{blah blah 

  blah blah} 
 No color in this case.

 \end{document}

I am sure I am making some simple mistake. Any help is appreciated. Here is the output

DBS
  • 599
  • 3
  • 6
  • 12

2 Answers2

39

\textcolor{<color>}{...} is a command that doesn't allow changes of paragraph (it is defined with \def instead of \long\def).

You must use {\color{<color>}...} instead.

\documentclass{article}
\usepackage{xcolor}
\usepackage{showframe} % Only for demo
\begin{document}
\textcolor{red}{blah blah blah} 

{\color{blue}blah blah 

 % A paragraph here 

 blah blah}

blah blah 
\end{document}

enter image description here

skpblack
  • 8,904
  • 3
  • 31
  • 42
15

I would recommend you define you own environment for paragraphs that are in color:

enter image description here

References

Code:

\documentclass{article}
\usepackage{xcolor}

\newenvironment{MyColorPar}[1]{% \leavevmode\color{#1}\ignorespaces% }{% }%

\begin{document} Normal text preceding.

\begin{MyColorPar}{red} blah blah

A paragraph here

blah blah \end{MyColorPar}

Normal text following. \end{document}

Peter Grill
  • 223,288
  • 3
    My impression is that this should be \leavevmode\color{#1}\ignorespaces, because of the well known problems of starting a new color in vertical mode. See http://tex.stackexchange.com/questions/47050/how-does-changing-colour-affect-spacing, for example – egreg Oct 15 '14 at 07:13
  • 1
    @egreg: Your impression? Really, just an impression? :-) Thanks for the correction. – Peter Grill Oct 15 '14 at 17:46
  • After adapting the \newenvironment to another problem, I found that, if the last line of the last paragraph reaches the right margin, an extra line is added. The solution given at https://tex.stackexchange.com/a/673970/187997 is to add \unskip; that is, change }{% to }{\unskip%. – Rick Smith Feb 04 '23 at 17:30