LaTeX color

StartLaTeX Topicsfont sizearrowsminipageitalicsboldtext colormatrixfontslistingstables

1 Xcolor usepackage

Many users don't just want to use black text on a white background with LaTeX, but also want to be able to change the color of the font or other elements. One package that is suitable for this is the xcolor package, which makes it quite easy to change the color of the font, for example. This is done with \usepackage{xcolor} as usual. However, it should be noted that a large number of colors are only available to the user when the corresponding option is set when xcolor is included.

1.1 Options

The option plays an essential role in the package. They not only activate most of the available colors, but also certain commands are only available when the corresponding option is set.

1.1.1 Color models

The first group of options refers to the color models. Per default, natural is set here, which means that the colors remain in their model, with the exception of RGB, HSB and Gray which are transferred to rgb, hsb and gray. If another option is set here, the colors will be transferred to the corresponding model.

Options that are transferred directly are rgb, cmy, cmyk, hsb and gray. The options RGB and HTML are transferred to rgb, HSB to hsb and Gray to gray.

1.1.2 Colors

The second group of options refers to the predefined colors and their use. The options dvipsnames, svgnames and x11names each load a set of predefined colors. The option table ensures that the colortbl usepackage is loaded, so that tables (rows, columns and cells) can also be colored. The hyperref option adapts the hyperref usepackage to the xcolor usepackage.

Options Description
rgb, cmy, cmyk, hsb and gray (RGB, HTML, HSB and Gray) Ütransfer all colors to the specified color model.
dvipsnames, svgnames and x11names Load a set of predefined colors each.
table Includes the colortbl usepackage and allows the use of colors within tables.
hyperref Adapt the hyperref usepackage to the usexcolor package.

1.2 xcolor without option

Without option i.e. only \usepackage{xcolor} the following 19 colors are available.
black darkgray gray lightgray white
yellow orange red purple pink
magenta violet blue cyan teal
green lime olive brown

1.3 xcolor with option dvipsnames

To be able to use these colors, the option dvipsnames must be set:

For example:


2 Applications

With xcolor you can now set pages, backgrounds, fonts, text, frames and fields in the available colors.

define a new color

With the command \definecolor{color name}{color set}{value} you can define your own colors.

Example: \definecolor{MyBlue}{rgb}{0.9,0.9,1}

\color command

The \color{Color} command changes the default color from black to the selected color. With \color{green} everything turns green, not only the font, but also elements like tables etc...

page color

The \pagecolor{Color} command changes the page color. For example \pagecolor{red} then the page becomes red instead of white.

text color

The font color or text color can be changed with \textcolor{Color}{Text} command. Example \textcolor{blue}{Text} Text

background color

A colored background box is created with \colorbox{Color}{Text}. For example the word text on a red background \colorbox{red}{Text}
text color & background color
For example, \colorbox{yellow}{\textcolor{red}{red text on yellow background}}
red text on yellow background

framed and colored background box

With the command \fcolorbox{Frame color}{Background color}{Content} a colored frame can be set around a colored background.

2.1 Tables

Within tables, individual cells, columns, and rows can be colored. To be able to use the commands, the option table must be set.

A & B & C \\
1 & 2 & 3 \\
A & B & C \\

2.2 further Applications

colored and framed equations
\fcolorbox{red}{white}{$a^{2} + b^{2} = c^{2}$}

a2 + b2 = c2

colored and framed listings
\item listing
\item key point 1
\item key point 2
\item enumeration
\item key point
\item key point

  • listing  
  • key point 1  
  • key point 2

  1. enumeration  
  2. key point
  3. key point


Contact   Privacy Policy   disclosures

accept decline

This website uses cookies and pixel tags to ensure you get the best experience on our website. By using this website, you consent to the use of cookies.learn more about cookies see also our privacy policy