1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463
|
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<!-- This document is an unofficial reference manual for LaTeX, a
document preparation system, version of October 2018.
This manual was originally translated from LATEX.HLP v1.0a in the
VMS Help Library. The pre-translation version was written by
George D. Greenwade of Sam Houston State University. The
LaTeX 2.09 version was written by Stephen Gilmore. The
LaTeX2e version was adapted from this by Torsten Martinsen. Karl
Berry made further updates and additions, and gratefully acknowledges
using Hypertext Help with LaTeX, by Sheldon Green, and
LaTeX Command Summary (for LaTeX 2.09) by
L. Botway and C. Biemesderfer (published by the TeX Users
Group as TeXniques number 10), as reference material. We also
gratefully acknowledge additional material appearing in
latex2e-reference by Martin Herbert Dietze. (From these references no
text was directly copied.)
Copyright 2007, 2008, 2009, 2010, 2011, 2012, 2013,
2014, 2015, 2016, 2017, 2018 Karl Berry.
Copyright 1988, 1994, 2007 Stephen Gilmore.
Copyright 1994, 1995, 1996 Torsten Martinsen.
Permission is granted to make and distribute verbatim copies of
this manual provided the copyright notice and this permission notice
are preserved on all copies.
Permission is granted to copy and distribute modified versions of this
manual under the conditions for verbatim copying, provided that the entire
resulting derived work is distributed under the terms of a permission
notice identical to this one.
Permission is granted to copy and distribute translations of this manual
into another language, under the above conditions for modified versions. -->
<!-- Created by GNU Texinfo 6.5, http://www.gnu.org/software/texinfo/ -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Color (LaTeX2e unofficial reference manual (October 2018))</title>
<meta name="description" content="Color (LaTeX2e unofficial reference manual (October 2018))">
<meta name="keywords" content="Color (LaTeX2e unofficial reference manual (October 2018))">
<meta name="resource-type" content="document">
<meta name="distribution" content="global">
<meta name="Generator" content="makeinfo">
<link href="latex2e_0.html#Top" rel="start" title="Top">
<link href="latex2e_30.html#Index" rel="index" title="Index">
<link href="latex2e_0.html#SEC_Contents" rel="contents" title="Table of Contents">
<link href="latex2e_0.html#Top" rel="up" title="Top">
<link href="latex2e_22.html#Graphics" rel="next" title="Graphics">
<link href="latex2e_20.html#g_t_005cusebox" rel="prev" title="\usebox">
<style type="text/css">
<!--
body {margin: 1em; margin-top: 0px; padding-top: 1px}
a.anchor {float: right}
a.summary-letter {text-decoration: none}
blockquote.indentedblock {margin-right: 0em}
blockquote.smallindentedblock {margin-right: 0em; font-size: smaller}
blockquote.smallquotation {font-size: smaller}
div.display {margin-left: 3.2em}
div.example {margin-left: 3.2em}
div.lisp {margin-left: 3.2em}
div.smalldisplay {margin-left: 3.2em}
div.smallexample {margin-left: 3.2em}
div.smalllisp {margin-left: 3.2em}
kbd {font-style: oblique}
pre.display {font-family: inherit}
pre.format {font-family: inherit}
pre.menu-comment {font-family: serif}
pre.menu-preformatted {font-family: serif}
pre.smalldisplay {font-family: inherit; font-size: smaller}
pre.smallexample {font-size: smaller}
pre.smallformat {font-family: inherit; font-size: smaller}
pre.smalllisp {font-size: smaller}
span.nolinebreak {white-space: nowrap}
span.roman {font-family: initial; font-weight: normal}
span.sansserif {font-family: sans-serif; font-weight: normal}
ul.no-bullet {list-style: none}
-->
</style>
</head>
<body id="top" lang="en">
<a name="Color" class="anchor"></a>
<a name="Color-1" class="anchor"></a>
<h2 class="chapter">Color</h2>
<a name="index-color" class="anchor"></a>
<p>You can add color to text, rules, etc. You can also have color in a box
or on an entire page and write text on top of it.
</p>
<p>Color support comes as an additional package. So put
<code>\usepackage{color}</code> in your document preamble to use the
commands described here.
</p>
<p>Many other packages also supplement LaTeX’s color abilities.
Particularly worth mentioning is <samp>xcolor</samp>, which is widely used and
significantly extends the capabilities described here, including adding
‘<samp>HTML</samp>’ and ‘<samp>Hsb</samp>’ color models.
</p>
<hr>
<a name="Color-package-options" class="anchor"></a>
<a name="color-package-options" class="anchor"></a>
<h3 class="section"><code>color</code> package options</h3>
<a name="index-color-package-options" class="anchor"></a>
<a name="index-options_002c-color-package" class="anchor"></a>
<p>Synopsis (must be in the document preamble):
</p>
<div class="example">
<pre class="example">\usepackage[<var>comma-separated option list</var>]{color}
</pre></div>
<p>When you load the <samp>color</samp> package there are two kinds of available
options.
</p>
<p>The first specifies the <em>printer driver</em>. LaTeX doesn’t contain
information about different output systems but instead depends on
information stored in a file. Normally you should not specify the
driver option in the document, and instead rely on your system’s
default. One advantage of this is that it makes the document portable
across systems. For completeness we include a list of the drivers. The
currently relevant ones are: <samp>dvipdfmx</samp>, <samp>dvips</samp>,
<samp>dvisvgm</samp>, <samp>luatex</samp>, <samp>pdftex</samp>, <samp>xetex</samp>. The two
<samp>xdvi</samp> and <samp>oztex</samp> are essentially aliases for <samp>dvips</samp>
(and <samp>xdvi</samp> is monochrome). Ones that should not be used for new
systems are: <samp>dvipdf</samp>, <samp>dvipdfm</samp>, <samp>dviwin</samp>,
<samp>dvipsone</samp>, <samp>emtex</samp>, <samp>pctexps</samp>, <samp>pctexwin</samp>,
<samp>pctexhp</samp>, <samp>pctex32</samp>, <samp>truetex</samp>, <samp>tcidvi</samp>,
<samp>vtex</samp> (and <samp>dviwindo</samp> is an alias for <samp>dvipsone</samp>).
</p>
<p>The second kind of options, beyond the drivers, are below.
</p>
<dl compact="compact">
<dt><code>monochrome</code></dt>
<dd><p>Disable the color commands, so that they do not generate errors but do
not generate color either.
</p>
</dd>
<dt><code>dvipsnames</code></dt>
<dd><p>Make available a list of 68 color names that are often used,
particularly in legacy documents. These color names were originally
provided by the <samp>dvips</samp> driver, giving the option name.
</p>
</dd>
<dt><code>nodvipsnames</code></dt>
<dd><p>Do not load that list of color names, saving LaTeX a tiny amount of
memory space.
</p>
</dd>
</dl>
<hr>
<a name="Color-models" class="anchor"></a>
<a name="Color-models-1" class="anchor"></a>
<h3 class="section">Color models</h3>
<a name="index-color-models" class="anchor"></a>
<p>A <em>color model</em> is a way of representing colors. LaTeX’s
capabilities depend on the printer driver. However, the <samp>pdftex</samp>,
<samp>xetex</samp>, and <samp>luatex</samp> printer drivers are today by far the
most commonly used. The models below work for those drivers. All but
one of these is also supported by essentially all other printer drivers
used today.
</p>
<p>Note that color combination can be additive or subtractive. Additive
mixes colors of light, so that for instance combining full intensities
of red, green, and blue produces white. Subtractive mixes pigments,
such as with inks, so that combining full intensity of cyan, magenta,
and yellow makes black.
</p>
<dl compact="compact">
<dd><a name="color-models-cmyk" class="anchor"></a></dd>
<dt><code>cmyk</code></dt>
<dd><p>A comma-separated list with four real numbers between 0 and 1,
inclusive. The first number is the intensity of cyan, the second is
magenta, and the others are yellow and black. A number value of 0 means
minimal intensity, while a 1 is for full intensity. This model is often
used in color printing. It is a subtractive model.
</p>
<a name="color-models-gray" class="anchor"></a></dd>
<dt><code>gray</code></dt>
<dd><p>A single real number between 0 and 1, inclusive. The colors are shades
of grey. The number 0 produces black while 1 gives white.
</p>
<a name="color-models-rgb" class="anchor"></a></dd>
<dt><code>rgb</code></dt>
<dd><p>A comma-separated list with three real numbers between 0 and 1,
inclusive. The first number is the intensity of the red component, the
second is green, and the third the blue. A number value of 0 means that
none of that component is added in, while a 1 means full intensity.
This is an additive model.
</p>
<a name="color-models-RGB" class="anchor"></a></dd>
<dt><code>RGB</code></dt>
<dd><p>(<samp>pdftex</samp>, <samp>xetex</samp>, <samp>luatex</samp> drivers) A comma-separated
list with three integers between 0 and 255, inclusive. This model is a
convenience for using <code>rgb</code> since outside of LaTeX colors are
often described in a red-green-blue model using numbers in this range.
The values entered here are converted to the <code>rgb</code> model by
dividing by 255.
</p>
<a name="color-models-named" class="anchor"></a></dd>
<dt><code>named</code></dt>
<dd><p>Colors are accessed by name, such as ‘<samp>PrussianBlue</samp>’. The list of
names depends on the driver, but all support the names ‘<samp>black</samp>’,
‘<samp>blue</samp>’, ‘<samp>cyan</samp>’, ‘<samp>green</samp>’, ‘<samp>magenta</samp>’, ‘<samp>red</samp>’,
‘<samp>white</samp>’, and ‘<samp>yellow</samp>’ (See the <code>dvipsnames</code> option in
<a href="#Color-package-options">Color package options</a>).
</p>
</dd>
</dl>
<hr>
<a name="Commands-for-color" class="anchor"></a>
<a name="Commands-for-color-1" class="anchor"></a>
<h3 class="section">Commands for color</h3>
<a name="index-color-package-commands" class="anchor"></a>
<p>These are the commands available with the <samp>color</samp> package.
</p>
<hr>
<a name="Define-colors" class="anchor"></a>
<a name="Define-colors-1" class="anchor"></a>
<h4 class="subsection">Define colors</h4>
<a name="index-color-1" class="anchor"></a>
<a name="index-define-color" class="anchor"></a>
<a name="index-color_002c-define" class="anchor"></a>
<p>Synopsis:
</p>
<div class="example">
<pre class="example">\definecolor{<var>name</var>}{<var>model</var>}{<var>specification</var>}
</pre></div>
<p>Give the name <var>name</var> to the color. For example, after this
</p>
<div class="example">
<pre class="example">\definecolor{silver}{rgb}{0.75,0.75,0.74}
</pre></div>
<p>you can use that color name with <code>Hi ho,
\textcolor{silver}{Silver}!</code>.
</p>
<p>This example gives the color a more abstract name, so it could change and
not be misleading.
</p>
<div class="example">
<pre class="example">\definecolor{logocolor}{RGB}{145,92,131} % RGB needs pdflatex
\newcommand{\logo}{\textcolor{logocolor}{Bob's Big Bagels}}
</pre></div>
<p>Often a document’s colors are defined in the preamble, or in the class
or style, rather than in the document body.
</p>
<hr>
<a name="Colored-text" class="anchor"></a>
<a name="Colored-text-1" class="anchor"></a>
<h4 class="subsection">Colored text</h4>
<a name="index-color-2" class="anchor"></a>
<a name="index-colored-text" class="anchor"></a>
<p>Synopses:
</p>
<div class="example">
<pre class="example">\textcolor{<var>name</var>}{...}
\textcolor[<var>color model</var>]{<var>color specification</var>}{...}
</pre></div>
<p>or
</p>
<div class="example">
<pre class="example">\color{<var>name</var>}
\color[<var>color model</var>]{<var>specification</var>}
</pre></div>
<p>The affected text gets the color. This line
</p>
<div class="example">
<pre class="example">\textcolor{magenta}{My name is Ozymandias, king of kings:}
Look on my works, ye Mighty, and despair!
</pre></div>
<p>causes the first half to be in magenta while the rest is in black. You
can use a color declared with <code>\definecolor</code> in exactly the same
way that we just used the builtin color ‘<samp>magenta</samp>’.
</p>
<div class="example">
<pre class="example">\definecolor{MidlifeCrisisRed}{rgb}{1.0,0.11,0.0}
I'm thinking about getting a \textcolor{MidlifeCrisisRed}{sports car}.
</pre></div>
<p>The two <code>\textcolor</code> and <code>\color</code> 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 <code>The moon is made of {\color{green}
green} cheese</code>, 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 <code>center</code> environment,
including the vertical and horizontal lines.
</p>
<div class="example">
<pre class="example">\begin{center} \color{blue}
\begin{tabular}{l|r}
UL &UR \\ \hline
LL &LR
\end{tabular}
\end{center}
</pre></div>
<p>You can use color in equations. A document might have this definition
in the preamble
</p>
<div class="example">
<pre class="example">\definecolor{highlightcolor}{RGB}{225,15,0}
</pre></div>
<p>and then contain this equation.
</p>
<div class="example">
<pre class="example">\begin{equation}
\int_a^b \textcolor{highlightcolor}{f'(x)}\,dx=f(b)-f(a)
\end{equation}
</pre></div>
<p>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.
</p>
<div class="example">
<pre class="example">Colors of \textcolor[rgb]{0.33,0.14,0.47}{Purple} and
{\color[rgb]{0.72,0.60,0.37} Gold} for the team.
</pre></div>
<p>The format of <var>color specification </var> depends on the color model
(see <a href="#Color-models">Color models</a>). For instance, while <code>rgb</code> takes three
numbers, <code>gray</code> takes only one.
</p>
<div class="example">
<pre class="example">The selection was \textcolor[gray]{0.5}{grayed out}.
</pre></div>
<p>Colors inside colors do not combine. Thus
</p>
<div class="example">
<pre class="example">\textcolor{green}{kind of \textcolor{blue}{blue}}
</pre></div>
<p>has a final word that is blue, not a combination of blue and green.
</p>
<hr>
<a name="Colored-boxes" class="anchor"></a>
<a name="Colored-boxes-1" class="anchor"></a>
<h4 class="subsection">Colored boxes</h4>
<a name="index-color-3" class="anchor"></a>
<a name="index-colored-boxes" class="anchor"></a>
<a name="index-box_002c-colored" class="anchor"></a>
<p>Synopses:
</p>
<div class="example">
<pre class="example">\colorbox{<var>name</var>}{...}
\colorbox[<var>model name</var>]{<var>box background color</var>}{...}
</pre></div>
<p>or
</p>
<div class="example">
<pre class="example">\fcolorbox{<var>frame color</var>}{<var>box background color</var>}{...}
\fcolorbox[<var>model name</var>]{<var>frame color</var>}{<var>box background color</var>}{...}
</pre></div>
<p>Make a box with the stated background color. The <code>\fcolorbox</code>
command puts a frame around the box. For instance this
</p>
<div class="example">
<pre class="example">Name:~\colorbox{cyan}{\makebox[5cm][l]{\strut}}
</pre></div>
<p>makes a cyan-colored box that is five centimeters long and gets its
depth and height from the <code>\strut</code> (so the depth is
<code>-.3\baselineskip</code> and the height is <code>\baselineskip</code>). This
puts white text on a blue background.
</p>
<div class="example">
<pre class="example">\colorbox{blue}{\textcolor{white}{Welcome to the machine.}}
</pre></div>
<p>The <code>\fcolorbox</code> commands use the same parameters as <code>\fbox</code>
(see <a href="latex2e_20.html#g_t_005cfbox-_0026-_005cframebox">\fbox & \framebox</a>), <code>\fboxrule</code> and <code>\fboxsep</code>, to
set the thickness of the rule and the boundary between the box interior
and the surrounding rule. LaTeX’s defaults are <code>0.4pt</code> and
<code>3pt</code>, respectively.
</p>
<p>This example changes the thickness of the border to 0.8 points. Note
that it is surrounded by curly braces so that the change ends at the end
of the second line.
</p>
<div class="example">
<pre class="example">{\setlength{\fboxrule}{0.8pt}
\fcolorbox{black}{red}{Under no circumstances turn this knob.}}
</pre></div>
<hr>
<a name="Colored-pages" class="anchor"></a>
<a name="Colored-pages-1" class="anchor"></a>
<h4 class="subsection">Colored pages</h4>
<a name="index-color-4" class="anchor"></a>
<a name="index-colored-page" class="anchor"></a>
<a name="index-page_002c-colored" class="anchor"></a>
<a name="index-background_002c-colored" class="anchor"></a>
<p>Synopses:
</p>
<div class="example">
<pre class="example">\pagecolor{<var>name</var>}
\pagecolor[<var>color model</var>]{<var>color specification</var>}
\nopagecolor
</pre></div>
<p>The first two set the background of the page, and all subsequent pages,
to the color. For an explanation of the specification in the second
form see <a href="#Colored-text">Colored text</a>. The third returns the background to normal,
which is a transparent background. (If that is not supported use
<code>\pagecolor{white}</code>, although that will make a white background
rather than the default transparent background.)
</p>
<div class="example">
<pre class="example"> ...
\pagecolor{cyan}
...
\nopagecolor
</pre></div>
</body>
</html>
|