Typevia
Color and Visual Design

Color Models and Definitions

This page goes deeper into how LaTeX represents and defines colors. It assumes you have read Introduction to color in LaTeX documents and know how to load the xcolor package and use \textcolor and \color for applying colors.


Understanding Color Models

To define custom colors, you must understand color models. A model is a mathematical way to describe a color using a set of numbers.

1. RGB (Red, Green, Blue)

The RGB model is "additive" and is used for digital screens. In xcolor, uppercase RGB expects integer values from 0 to 255 (familiar from web and image editors).

  • 0,0,0 is black.
  • 255,255,255 is white.

2. rgb (lowercase)

The lowercase rgb model also represents red, green, and blue but uses decimal values between 0 and 1.

  • 0,0,0 is black.
  • 1,1,1 is white.

Use rgb when you prefer normalized values or when copying from tools that use 0–1 ranges.

3. cmyk (Cyan, Magenta, Yellow, Black)

The CMYK model is "subtractive" and is the standard for professional printing. Values are decimals between 0 and 1.

  • 0,0,0,0 is white (the paper).
  • 0,0,0,1 is pure black ink.

Use cmyk when preparing documents for a print shop so colors match the final output.

4. HTML / hex

Commonly used in web design, this uses a six-digit hexadecimal code without the leading # (e.g., FF5733). Ideal for matching brand colors from websites or style guides.

5. gray

A simple model for shades of gray, using a single decimal between 0 (black) and 1 (white).


Defining Custom Colors

You define colors in the preamble using the \definecolor command:

Syntax: \definecolor{name}{model}{values}

Example: Custom Color Definitions

\documentclass{article}
\usepackage{xcolor}

% Defining colors using different models
\definecolor{DeepSeaBlue}{rgb}{0, 0.2, 0.5}
\definecolor{SoftPink}{RGB}{255, 182, 193} % Uppercase RGB = 0-255 scale
\definecolor{ForestGreen}{cmyk}{0.91, 0, 0.88, 0.12}
\definecolor{MyOrange}{HTML}{FF8C00}
\definecolor{LightGray}{gray}{0.9}

\begin{document}

\textcolor{DeepSeaBlue}{This is a custom rgb blue.}

\textcolor{SoftPink}{This is a custom RGB pink using 0-255 values.}

\textcolor{ForestGreen}{This is a CMYK green, suited for printing.}

\textcolor{MyOrange}{This orange was defined via an HTML hex code.}

\end{document}

Tip: xcolor distinguishes between rgb (decimals 0–1) and RGB (integers 0–255). The case of the model name must match the values you provide.


Advanced Features: Mixing and Tints

One of the most powerful features of xcolor is mixing colors or creating tints on the fly without defining a new color every time.

Tints and Shades

Add !percentage after a color name to mix it with white:

  • blue!50 means 50% blue and 50% white.
  • red!20 means 20% red and 80% white (a very light pink).

Mixing Two Colors

Use the syntax color1!percentage!color2:

  • red!30!yellow means 30% red and 70% yellow.
  • green!40!black gives a dark forest green.

Example: Mixing and Tints

\documentclass{article}
\usepackage{xcolor}

\begin{document}

\begin{itemize}
    \item \textcolor{blue!100}{Blue 100\%}
    \item \textcolor{blue!75}{Blue 75\%}
    \item \textcolor{blue!50}{Blue 50\%}
    \item \textcolor{blue!25}{Blue 25\%}
    \item \textcolor{red!50!blue}{A mix of 50\% red and 50\% blue (purple)}
    \item \textcolor{green!40!black}{A dark forest green (40\% green, 60\% black)}
\end{itemize}

\end{document}

Model-Specific Tips

  • Screen vs. print: For documents viewed on screens (PDFs, web), use rgb, RGB, or HTML. For professional printing, define critical colors with cmyk so they match the press.
  • More named colors: Load options such as dvipsnames or svgnames to get extra predefined names without defining them yourself: \usepackage[dvipsnames]{xcolor}.
  • "Undefined color" errors: Check for typos, that xcolor is loaded, and that you have enabled the option for any palette (e.g. dvipsnames) whose color names you use.