How to Define and Use Your Colors in LaTeX
Description
The xcolor
package allows users to employ predefined colors, but users can also define and use their own colors. By including \definecolor{color name}{color space}{values}
in the preamble, you can define custom colors. The color spaces include rgb
, cmyk
, HTML
, gray
, among others.
\definecolor{color name}{gray}{gray}
: Definition of grayscale color\definecolor{color name}{rgb}{r,g,b}
: Definition of RGB color\definecolor{color name}{cmyk}{c,m,y,k}
: Definition of CMYK color\definecolor{color name}{RGB}{R, G, B}
: Definition of RGB color\definecolor{color name}{HTML}{RRGGBB}
: Definition of HTML color
Here, gray
, r
, g
, b
, c
, y
, m
, and k
are values ranging between to . R
, G
, and B
are values ranging from to , and RRGGBB
refers to the RGB code expressed in hexadecimal format.
An example is shown below.
\documentclass{article}
\usepackage{xcolor}
\definecolor{my_gray}{gray}{0.8}
\definecolor{my_rgb}{rgb}{0.8,0.2,0.2}
\definecolor{my_cmyk}{cmyk}{0.8,0.5,0.3,0.4}
\definecolor{my_RGB}{RGB}{155, 15, 200}
\definecolor{my_HTML}{HTML}{BCE55C}
\begin{document}
This is {\color{my_gray}gray} text.
This is {\color{my_rgb}rgb} text.
This is {\color{my_cmyk}cmyk} text.
This is {\color{my_RGB}RGB} text.
This is {\color{my_HTML}HTML} text.
\end{document}