You can write text in different colors using the xcolor package in LaTeX. The command for this is \textcolor{Color}{Text}
, and by default, you have access to several colors:
This LaTeX example demonstrates how to color text using the xcolor package. The xcolor package provides various predefined colors that you can apply to your text. To color text, use the \textcolor
command followed by the color name enclosed in curly braces. For example, \textcolor{red}{text}
will display "text" in red color.
Additionally, you can create colored boxes around text using the \fcolorbox
command. It takes two arguments: the border color and the background color. For instance, \fcolorbox{black}{white}{\textcolor{black}{text}}
will create a white box with a black border containing the word "text" in black color.
\documentclass{article} \usepackage{xcolor} \begin{document} \textcolor{red}{red}, \textcolor{green}{green}, \textcolor{blue}{blue}, \textcolor{cyan}{cyan}, \textcolor{magenta}{magenta}, \textcolor{yellow}{yellow}, \textcolor{black}{black}, \fcolorbox{black}{white}{\textcolor{black}{white}}, \textcolor{darkgray}{darkgray}, \textcolor{gray}{gray}, \textcolor{lightgray}{lightgray} \end{document}
In this example, we've used the \textcolor
command to change the color of text to different predefined colors. This package not only allows you to change the color of text but also to modify the color of the page itself (hence the text color "white") and create colored boxes and borders.