Let
X
Journal

How to Color Text & Tables in LaTeX (xcolor)

SPECIMEN IDLETX-SPEC-LATE
DATE RECORDEDJun 4, 2026
READING COMPLEXITY2 min read
TAG INDEX
latexcolorxcolortutorial
Document Abstract

To color text in LaTeX, load the xcolor package and use \textcolor{red}{text}. Color table rows, cells, and define custom colors with HTML hex codes.

To color text in LaTeX, load the xcolor package and use \textcolor{red}{text} for a span or \color{blue} to switch color until the end of the group. xcolor also colors table rows and cells and lets you define custom colors from HTML hex codes. Here's the full toolkit, plus an accessibility note.

1. Color text

\usepackage{xcolor}
...
This is \textcolor{red}{important} and this is {\color{blue} a blue phrase}.

\textcolor{color}{text} colors one span; {\color{color} ...} colors everything until the closing brace.

2. Built-in and custom colors

xcolor ships red, blue, green, gray, orange, purple, and more. Mix shades with !:

\textcolor{blue!50}{half-strength blue}
\textcolor{red!70!black}{dark red}

Define your own from a hex code:

\definecolor{brandblue}{HTML}{1A73E8}
\textcolor{brandblue}{on-brand text}

3. Color tables

\usepackage[table]{xcolor}    % the [table] option
...
\rowcolors{1}{gray!15}{white}  % zebra striping from row 1
\begin{tabular}{ll}
  ...
\end{tabular}

| Command | Effect | |---|---| | \rowcolors{1}{a}{b} | Alternate row colors | | \rowcolor{gray!20} | One row | | \cellcolor{yellow} | One cell | | \columncolor{blue!10} | A column (in the spec) |

See the tables guide for structure.

4. Colored links and code

xcolor underpins colored hyperlinks via hyperref (linkcolor=blue) and syntax highlighting in code listings. It's a dependency of many packages.

5. Use color responsibly

Color prints and renders fine, but don't rely on it alone — it vanishes in grayscale and challenges color-blind readers. Pair it with bold, a symbol, or a label for anything meaningful. Many journals require black body text and allow color only in figures, so check the guidelines. Color works well for Beamer slides and accents on a resume.

→ Pick colors and see them render instantly in LetX.


Written by Shihab Shahriar Antor — AI Engineer & Founder of Shahriar Labs, maker of LetX.

Frequently Asked Questions

How do I define a custom color with a hex code in LaTeX?

Load xcolor and define the color: \definecolor{brandblue}{HTML}{1A73E8} creates a color from a six-digit hex code, then \textcolor{brandblue}{text} uses it. You can also define colors in the RGB model with \definecolor{name}{RGB}{26,115,232} (values 0–255) or rgb with values 0–1. The HTML model is easiest when matching a brand or web palette, since you paste the same hex you use in CSS.

How do I color alternate rows in a table?

Load xcolor with the table option — \usepackage[table]{xcolor} — then use \rowcolors{1}{gray!15}{white} before a tabular to shade odd and even rows differently starting from row 1. For a single row, \rowcolor{gray!20} at the start of that row works, and \cellcolor{yellow} colors one cell. The table option pulls in colortbl, which provides these row and cell coloring commands.

Will colored text print correctly and is it accessible?

Colored text prints fine on a color printer and renders in any PDF viewer, but don't rely on color alone to convey meaning, since it disappears in grayscale printing and is hard for color-blind readers. Pair color with another cue — bold, a symbol, or a label — for anything important. For academic submissions, check the journal's rules; some require black text in the body and allow color only in figures.