LaTeX/Packages/Color
From Wikibooks, the open-content textbooks collection
The package color adds the support for colored text: LaTeX does not support it by default. The best approach is to define the colors you want to use at the beginning of your document and then you can reference them whenever you want. For example, you can use them to type colored text or as an argument of an other package that supports colors as arguments (for example, see the listings package). There are some standard colors that are already defined within the package, they are white, black, red, green, blue, cyan, magenta, yellow; you can reference them simply typing their name. You can define your own colors with:
\definecolor{name}{model}{color-spec}
- name is the name of the color; you can call it as you like
- model is the way you describe the color
- color-spec is the description of the color
The models you can use to describe the color are the following:
| model: | description: | color-spec: | example: |
| gray | you can only define shades of gray | just one number between 0 (black) and 1 (white), so 0.95 will be very light gray, 0.30 will be dark gray | \definecolor{light-gray}{gray}{0.95} |
| rgb | you refer to the Red-Green-Blue model | three number given in the form red,green,blue; the quantity of each color is represented with a number between 0 and 1 | \definecolor{orange}{rgb}{1,0.5,0} |
| cmyk | you refer to the Cyan Magenta Yellow blacK model | four numbers given in the form cyan,magenta,yellow,black | \definecolor{orange}{cmyk}{0,0.5,1,0} |
The simplest way to type colored text is by:
\textcolor{declared-color}{text}
where declared-color is a color that was defined before by \definecolor. Another possible way is by
\color{declared-color}
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:
this is standard black text, {\color{red} this will look red}, and this will look black again.
The difference between \textcolor and \color is the same difference between \texttt and \ttfamily, you can use the one you prefer.
Finally, you can also change the background color of the whole page by:
\pagecolor{declared-color}

