Synopses:
\textcolor{name}{...} \textcolor[color model]{color specification}{...}
or
\color{name} \color[color model]{color specification}
The affected text gets the color. This line
\textcolor{magenta}{My name is Ozymandias, King of Kings;} Look on my works, ye Mighty, and despair!
causes the first half to be in magenta while the rest is in black. You
can use a color declared with \definecolor
in exactly the same
way that we just used the builtin color ‘magenta’.
\definecolor{MidlifeCrisisRed}{rgb}{1.0,0.11,0.0} I'm thinking about getting a \textcolor{MidlifeCrisisRed}{sports car}.
The two \textcolor
and \color
differ in that the first is
a command form, enclosing the text to be colored as an argument. Often
this form is more convenient, or at least more explicit. The second
form is a declaration, as in The moon is made of {\color{green}
green} cheese
, so it is in effect until the end of the current group
or environment. This is sometimes useful when writing macros or as
below where it colors everything inside the center
environment,
including the vertical and horizontal lines.
\begin{center} \color{blue} \begin{tabular}{l|r} UL &UR \\ \hline LL &LR \end{tabular} \end{center}
You can use color in equations. A document might have this definition in the preamble
\definecolor{highlightcolor}{RGB}{225,15,0}
and then contain this equation.
\begin{equation} \int_a^b \textcolor{highlightcolor}{f'(x)}\,dx=f(b)-f(a) \end{equation}
Typically the colors used in a document are declared in a class or style but sometimes you want a one-off. Those are the second forms in the synopses.
Colors of \textcolor[rgb]{0.33,0.14,0.47}{Purple} and {\color[rgb]{0.72,0.60,0.37}Gold} for the team.
The format of color specification depends on the color model
(see Color models). For instance, while rgb
takes three
numbers, gray
takes only one.
The selection was \textcolor[gray]{0.5}{grayed out}.
Colors inside colors do not combine. Thus
\textcolor{green}{kind of \textcolor{blue}{blue}}
has a final word that is blue, not a combination of blue and green.