LaTeX
  • How I learn LaTeX?
  • Installation and Customization
    • Online
    • Offline
  • LaTeX Basics
  • Text Manipulation
    • Fonts, Size and Styles
  • Math Manipulation
  • Advanced Math Manipulation
  • Lists
  • Tables
  • Pictures, Figures
  • Unit in LaTeX
  • Document Structure
  • Document Formatting
    • Headers and Footers, Page Numbering
    • Spacing in Paragraphs
    • Page size, Margins
    • Coloring
    • Footnotes
  • Multi-file LaTeX project
Powered by GitBook
On this page
  • The xcolor package
  • Supported colors
  1. Document Formatting

Coloring

This article explains how to use colour in your LaTeX document via the color or xcolor packages.

There are 2 packages that supports the process of coloring your document in LaTeX\LaTeXLATE​X: color and xcolor. While both packages provide a common set of commands for colour manipulation, but xcolor is more flexible and supports a larger number of colour models, so is the recommended approach.

The xcolor package

Let's look at xcolor in action:

\documentclass{article}
\usepackage{xcolor}
\begin{document}
This example shows how to use the \texttt{xcolor} package 
to change the colour of \LaTeX{} page elements.

\begin{itemize}
\color{magenta}
\item First item
\item Second item
\end{itemize}


The background colour of text can also be \textcolor{red}{easily} set. For 
instance, you can change use an \colorbox{orange}{orange background} and then continue typing.
\end{document}

This example produces the following output:

  • \color{magenta} - set the magenta color for the following block of text - in this case is itemize

  • \textcolor{red}{easily}: Changes the colour of inline text. This command takes two parameters, the colour to use and the text whose colour is changed.

  • \colorbox{orange}{orange background}: Changes the background colour of the text passed in as the second argument.

Supported colors

If loaded with not special options, the default color pallete of xcolor is:

However, you can get access to more named colors via the following options:

  • dvipsnames: loads 68 named colours (CMYK)

  • svgnames: loads 151 named colours (RGB)

  • x11names: loads 317 named colours (RGB)

For example, if you import the xcolor package with: \usepackage[dvipsnames]{xcolor}, you will get the following colors:

For reference:

PreviousPage size, MarginsNextFootnotes

Last updated 1 year ago

http://mirrors.ctan.org/macros/latex/contrib/xcolor/xcolor.pdf