latex

How to Change a Text Color in LaTeX

If you format a text in the document, it can make the information visually appealing and it can quickly grab the reader’s attention. Changes in text color help you to highlight the important stuff such as warnings, hyperlinks, etc. However, it can mess up the document if you overuse the colored text.

That’s why many document processors like LaTeX provide a simple way to change a text color easily. If you want to learn the methods to change the text color in LaTeX, this tutorial is for you. Here, we will include the different approaches to changing the text color in LaTeX.

How to Change a Text Color in LaTeX

Let’s start with the simple method to change the text color using the xcolor \usepackage. Here is the following example:

\documentclass{article}

\usepackage{xcolor}

\begin{document}

Human blood contains the followings:

\begin{itemize}

\color{purple}

\item Red blood cells

\item White blood cells

\item Platelets

\end{itemize}

\end{document}

Output:

In the given source code, you can type any color name to change the text color in the document of LaTeX. If you want to change the colors with the color code, use the following source code:

\documentclass{article}

\usepackage{xcolor}

\definecolor{Info1}{rgb}{0.5, 0.8, 0.7}

\definecolor{Info2}{rgb}{0.8, 0.5, 0.7}

\definecolor{Info3}{rgb}{0.5, 0.7, 0.8}

\begin{document}

Here is the list of popular Linux distros:

\begin{itemize}

\item \textcolor{Info1}{Ubuntu}

\item \textcolor{Info2}{Fedora}

\item \textcolor{Info3}{Arch Linux}

\end{itemize}

\end{document}

Output:

In the previous source code, the {rgb} stands for red, green, and blue. You can change their codes as per the requirements. If you don’t know the codes, you can search for them online.

There is another method where you can define the color of the text while writing the \usepackage name:

\documentclass{article}

\usepackage[dvipsnames]{xcolor}

\colorlet{info1}{Yellow}

\definecolor{info2}{HTML}{FFC90E}

\begin{document}

\begin{itemize}

\item \textcolor{info1}{Yellow}

\item \textcolor{info2}{Tangerine Yellow}

\end{itemize}

\end{document}

Output:

Conclusion

In this tutorial, we explained how to change the text color in LaTeX. LaTeX contains a simple source code to change the text colors, but make sure that you write the codes correctly. Otherwise, you may get some errors while compiling the document in LaTeX. Moreover, check our official website if you want to learn more about LaTeX.

About the author

Prateek Jangid

A passionate Linux user for personal and professional reasons, always exploring what is new in the world of Linux and sharing with my readers.