Sarmate.net Sarmate.net
Home Features Pricing Documentation Contact
Log in Sign up

Changing text color in LaTeX

The xcolor package allows you to color text, backgrounds and define custom colors. It is included in all modern LaTeX distributions.

Coloring text with \textcolor

LaTeX
Texte \textcolor{red}{en rouge} et \textcolor{blue}{en bleu}.

\textcolor{green!60!black}{Vert foncé avec mélange.}

{\color{orange} Tout ce paragraphe est en orange.}

Colored background and highlighting

LaTeX
Texte avec \colorbox{yellow}{fond jaune}.

\colorbox{blue!20}{Fond bleu clair, texte noir.}

\fcolorbox{red}{red!10}{Bordure rouge, fond rose.}

Defining custom colors

Use \definecolor to create custom colors in RGB, HTML or CMYK.

LaTeX
\definecolor{monbleu}{HTML}{2563EB}
\definecolor{monvert}{rgb}{0.1, 0.6, 0.3}

\textcolor{monbleu}{Texte en bleu personnalisé.}

\textcolor{monvert}{Texte en vert personnalisé.}

Predefined colors

ColorCommandMixing
Rouge\textcolor{red}{...}red!50 = 50% rouge
Bleu\textcolor{blue}{...}blue!30!green = mélange
Vert\textcolor{green}{...}green!70!black = foncé
Orange\textcolor{orange}{...}orange!20 = clair
Violet\textcolor{violet}{...}violet!50!white
Tip: mixing notation The syntax color1!percentage!color2 mixes two colors. For example, blue!30!white gives a light blue (30% blue, 70% white).

Test your knowledge

3 questions to check what you have learned.

1

Which package must be loaded to color text?

The xcolor package provides the color commands; textcolor and colors do not exist.

2

Which command colors a word red?

\textcolor{color}{text} takes two brace arguments. \color{red} changes the color until the end of the group but takes no text argument.

3

Which command defines a custom color?

\definecolor{name}{model}{value} creates a color (models HTML, rgb, cmyk...). \newcolor and \setcolor do not exist.

Try it in Sarmate

Edit, compile and download your LaTeX documents directly in your browser.

Open the editor