LaTeX/Colors

Adding colors to your text is supported by the xcolor package (supersedes package ). Using this package, you can set the font color, text background, or page background. You can choose from predefined colors or define your own colors using RGB, Hex, or CMYK. Mathematical formulas can also be colored.

Adding the xcolor package
To make use of these features, the package must be imported. starts from the basic facilities of the package and extends it.

The package allows you to use the names of 19 base colors (black, white, blue, green, yellow, red etc.); these names are always available. Besides, the package has some options to get more predefined colors, which should be added globally. allows you to access more than 60 colors, and allows access to about 150 colors. If you need more color names, then you may also want to look at the option that offers more than 300 colors.

The option allows colors to be added to tables.

Entering colored text
The simplest way to type colored text is by:

where is a color that, if necessary, was previously defined by.

Another possible way by

that will switch the standard text color to the color you want. It will work until the end of the current TeX group. For example:

The difference between

and

is the same as that between

and , you can use the one you prefer. The environment allows the text to run over multiple lines and other text environments whereas the text in  must all be one paragraph and not contain other environments.

You can change the background color of the whole page by:

Entering colored background for the text
If the background color and the text color is changed, then:

There is also \fcolorbox to make framed background color in yet another color:

Predefined colors
The predefined color names are black, blue, brown, cyan, darkgray, gray, green, lightgray, lime, magenta, olive, orange, pink, purple, red, teal, violet, white, yellow. There may be other pre-defined colors on your system, but these should be available on all systems.

If you would like a color not pre-defined, you can use one of the 68 dvips colors, or define your own. These options are discussed in the following sections

The 68 standard colors known to dvips
Invoke the package with the usenames and dvipsnames option. If you are using or  package you must declare the xcolor package before that, otherwise it will not work.

This above syntax may result in an error if you are using beamer with. To go around it, include usenames and dvipsnames options when defining the document class.

Be wary that the below color names are case-sensitive. For example, raises an "undefined color" error, but  works fine. Table can be sorted by color name, by hue, by saturation, or by lightness.

Defining new colors
If the predefined colors are not adequate, you may wish to define your own.

Place
Define the colors in the preamble of your document. (Reason: do so in the preamble, so that you can already refer to them in the preamble, which is useful, for instance, in an argument of another package that supports colors as arguments, such as the listings package.)

Method
You need to include the package in your preamble to define new colors. In the abstract, the colors are defined following this scheme:

where:
 * name is the name of the color; you can call it as you like
 * model is the way you describe the color, and is one of gray, rgb, RGB, HTML, and cmyk.
 * color-spec is the description of the color

Color Models
Among the models you can use to describe the color are the following (several more are described in the xcolor manual):

Examples
To define a new color, follow the following example, which defines orange for you, by setting the red to the maximum, the green to one half (0.5), and the blue to the minimum:

The following code should give a similar results to the last code chunk.

If you loaded the package, you can define colors upon previously defined ones.

The first specifies 20 percent blue and 80 percent white; the second is a mixture of 20 percent blue and 80 percent black; and the last one is a mixture of (20*0.3) percent blue, ((100-20)*0.3) percent black and (100-30) percent green.

also features a handy command to define colors from color mixes:

Using color specifications directly
Normally one would predeclare all the colors as above, but sometimes it is convenient to directly use a color without naming it first. To achieve this, and have an alternative syntax specifying the model in square brackets, and the color specification in curly braces. For example:

Creating / Capturing colors
You may want to use colors that appear on another document, web pages, pictures, etc. Alternatively, you may want to play around with rgb values to create your own custom colors.

Image processing suites like the free GIMP suite for Linux/Windows/Mac offer color picker facilities to capture any color on your screen or synthesize colors directly from their respective rgb / hsv / hexadecimal values.

Smaller, free utilities also exist:
 * Linux/BSD: The gcolor2 tool (usually also available in repositories)
 * Linux/BSD: in newer systems you may want to use gcolor3 tool (usually also available in repositories)
 * Microsoft Windows: The open-source Color Selector tool.
 * Apple Macs: Hex Color Picker for creating custom colors and the built-in DigitalColor Meter for capturing colors on screen.
 * Online utilities: See here for a Wikipedia article with several external links

Spot colors
Spot colors are customary in printing. They usually refer to pre-mixed inks based on a swatchbook (like Pantone, TruMatch or Toyo). The package extends xcolor to provide real spot colors (CMYK and CIELAB). They are defined with, say: