How to Use Colors in LaTeX: The xcolor Package
Explanation
\usepackage{color}
In $\LaTeX$, the most basic package that allows the use of colors is color
. You can add \usepackage{color}
to the preamble and use it as {\color{color}content}
. The available colors are as follows.
$$ \begin{array}{lll} \color{black}\colorbox{black}{\phantom{colorbox}}black& \color{blue}\colorbox{blue}{\phantom{colorbox}}blue& \color{cyan}\colorbox{cyan}{\phantom{colorbox}}cyan\\ \color{green}\colorbox{green}{\phantom{colorbox}}green& \color{magenta}\colorbox{magenta}{\phantom{colorbox}}magenta& \color{red}\colorbox{red}{\phantom{colorbox}}red\\ \color{white}\colorbox{white}{\phantom{colorbox}} \color{black}{white}& \color{yellow}\colorbox{yellow}{\phantom{colorbox}}yellow \end{array} $$
\documentclass{article}
\usepackage{color}
\begin{document}
This is {\color{red}red} text.
\end{document}
$$ \text{This is } \textcolor{red}{\text{red}} \text{ text.} $$
\usepackage{xcolor}
By using xcolor
, you can utilize more colors.
$$ \begin{array}{llll} \color{black}\colorbox{black}{\phantom{colorbox}}black& \color{blue}\colorbox{blue}{\phantom{colorbox}}blue& \color{brown}\colorbox{brown}{\phantom{colorbox}}brown& \color{cyan}\colorbox{cyan}{\phantom{colorbox}}cyan \\ \color{darkgray}\colorbox{darkgray}{\phantom{colorbox}}darkgray& \color{gray}\colorbox{gray}{\phantom{colorbox}}gray& \color{green}\colorbox{green}{\phantom{colorbox}}green& \color{lightgray}\colorbox{lightgray}{\phantom{colorbox}}lightgray \\ \color{lime}\colorbox{lime}{\phantom{colorbox}}lime& \color{magenta}\colorbox{magenta}{\phantom{colorbox}}magenta& \color{olive}\colorbox{olive}{\phantom{colorbox}}olive& \color{orange}\colorbox{orange}{\phantom{colorbox}}orange\\ \color{pink}\colorbox{pink}{\phantom{colorbox}}pink& \color{purple}\colorbox{purple}{\phantom{colorbox}}purple& \color{red}\colorbox{red}{\phantom{colorbox}}red& \color{teal}\colorbox{teal}{\phantom{colorbox}}teal\\ \color{violet}\colorbox{violet}{\phantom{colorbox}}violet& \color{white}\colorbox{white}{\phantom{colorbox}} \color{black}{white}& \color{yellow}\colorbox{yellow}{\phantom{colorbox}}yellow& \end{array} $$
\documentclass{article}
\usepackage{xcolor}
\begin{document}
This is {\color{olive}olive} text.\\
This is {\color{orange}orange} text.\\
\end{document}
$$ \text{This is } \textcolor{olive}{\text{olive}} \text{ text.}\\ \text{This is } \textcolor{orange}{\text{orange}} \text{ text.} $$
\usepackage[dvipsnames]{xcolor}
By adding [dvipsnames]
to the options, you can access a wider array of colors. The options and the number of available colors are as follows:
[dvipsnames]
: 68 CMYK colors[svgnames]
: 151 RGB colors[x11names]
: 317 RGB colors
The colors available in [dvipsnames]
are as follows, and the rest can be found in the official document.