Document Fundamentals

Colors

Learn how to add colors to text, backgrounds, and define custom colors in LaTeX using the xcolor package.

Adding colors to your text is supported by the xcolor package (supersedes package color). 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 xcolor package must be imported. xcolor starts from the basic facilities of the color package and extends it.

\usepackage{xcolor}

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. dvipsnames allows you to access more than 60 colors, and svgnames allows access to about 150 colors. If you need more color names, then you may also want to look at the x11names option that offers more than 300 colors.

The table option allows colors to be added to tables.

Entering Colored Text

The simplest way to type colored text is:

\textcolor{declared-color}{text}

where declared-color is a color that, if necessary, was previously defined by \definecolor.

Another possible way:

{\color{declared-color}some text}

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

\emph{some black text, {\color{red}followed by a red fragment} }, going black again.

The difference between \textcolor and \color is the same as that between \texttt and \ttfamily. The \color environment allows the text to run over multiple lines and other text environments whereas the text in \textcolor must all be one paragraph and not contain other environments.

You can change the background color of the whole page:

\pagecolor{declared-color}

Entering Colored Background for the Text

\colorbox{declared-color}{text}

If the background color and the text color is changed:

\colorbox{declared-color1}{\color{declared-color2}text}

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

\fcolorbox{declared-color-frame}{declared-color-background}{text}

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.

The 68 Standard Colors Known to dvips

Invoke the package with the usenames and dvipsnames option:

\usepackage[dvipsnames]{xcolor}

Note: If you are using beamer with tikz, include usenames and dvipsnames options when defining the document class:

\documentclass[usenames,dvipsnames]{beamer}

Be wary that the below color names are case-sensitive. For example, \color{olivegreen} raises an "undefined color" error, but \color{OliveGreen} works fine.

Defining New Colors

Place

Define the colors in the preamble of your document.

Method

\definecolor{name}{model}{color-spec}

where:

  • name is the name of the color
  • model is one of gray, rgb, RGB, HTML, and cmyk
  • color-spec is the description of the color

Color Models

ModelDescriptionExample
grayShades of gray (0-1)\definecolor{light-gray}{gray}{0.95}
rgbRed, Green, Blue (0-1)\definecolor{orange}{rgb}{1,0.5,0}
RGBRed, Green, Blue (0-255)\definecolor{orange}{RGB}{255,127,0}
HTMLRed, Green, Blue (00-FF)\definecolor{orange}{HTML}{FF7F00}
cmykCyan, Magenta, Yellow, Black (0-1)\definecolor{orange}{cmyk}{0,0.5,1,0}

Examples

\definecolor{orange}{rgb}{1,0.5,0}

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

\color{blue!20}
\color{blue!20!black}
\color{blue!20!black!30!green}

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

\colorlet{notgreen}{blue!50!yellow}

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:

{\color[rgb]{1,0,0} This text will appear red-colored}
\textcolor[rgb]{0,1,0}{This text will appear green-colored}

Creating / Capturing 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 or gcolor3 tools
  • 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

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 colorspace extends xcolor to provide real spot colors (CMYK and CIELAB):

\definespotcolor{mygreen}{PANTONE 7716 C}{.83, 0, .40, .11}
Copyright © 2026