10

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

  • Could you bring us a full MWE? – Aradnix Oct 15 '14 at 4:49
  • I am not sure I understand your comment ...MWE? – DBS Oct 15 '14 at 4:51
  • I mean a minimal working example (MWE) that illustrates your problem. It will be much easier for us to reproduce your situation and find out what the issue is when we see compilable code, starting with \documentclass{...} and ending with \end{document}. – Aradnix Oct 15 '14 at 4:53
  • I take it you ignored the error your MWE produces? – Joseph Wright Oct 15 '14 at 18:28
23

\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

  • 1
    Thanks. Just for info.. are their any cases where \textcolor is more favorable than {\color}? – DBS Oct 15 '14 at 5:14
  • 1
    You probably mean \long\def and not \edef. – egreg Oct 15 '14 at 7:11
  • @egreg Yes, thanks. I meant \long\def, fixed. – skpblack Oct 15 '14 at 10:28
10

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}
  • 2
    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 tex.stackexchange.com/questions/47050/…, for example – egreg Oct 15 '14 at 7:13
  • @egreg: Your impression? Really, just an impression? :-) Thanks for the correction. – Peter Grill Oct 15 '14 at 17:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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