Javatpoint Logo
Javatpoint Logo

Latex Colors

The xcolor package supports adding colors to your text. Using this, you can set the background, font color, and the page background. You can choose colors from the predefined colors or can create your color using RGB. The formulas of mathematics can also be colored.

The package which is imported in the code or program is written as:

The commands used to access different numbers of colors are listed below:

  • usenames: It allows access to16 base colors.
  • dvipsnames: It allows access to 64 more colors.
  • svgnames: It allows access to about 150 colors.
  • x11names: It offers more than 300 colors.

These commands mentioned above are declared in the code as:

The commands for entering the colored text are listed below:

There are two ways of typing the colored text. One is by using the \textcolorcommand, and another is by using the \color command.

The textcolor command is declared as \textcolor{mentioned-color}{text}.

The color command is declared as {\color{mentioned-color}some text}.

The textcolor command is used for all in one paragraph, while the color command is used for the text to run over other tex environments and the multiple lines.

To change the background color, you can use the command \pagecolor{mentioned-color}. This command colors the background of a whole page.

To color the background of the text, you can use the \colorbox{mentioned-color}{text} command.

If you want to change both the background and the text color, you can use the command in a way as mentioned below:

The primary colors used everywhere or which are the root of all the colors are red, yellow, and blue(RYB). The three secondary colors are orange, purple, and green, which is formed by mixing two primary colors. There are six tertiary colors, which are formed by the mixing of primary and secondary colors.

The predefined colors available on all the systems are listed below:

Latex Colors

The other predefined colors are listed below:

Latex Colors

Let's consider a simple example to color the text. The code is given below:

Output:

Latex Colors

The code to color the different lines is given below:

Output:

Latex Colors

New Colors

There are also some colors. If these colors are not adequate, then you can create your color.

To define new colors in the package, you need to include the xcolor package. The command used to create new colors is:

Here, specifications signify the description of the color, and the prototype is the model. There are five basic models or prototypes that are gray, rgb, RGB, HTML, cmyk. The range of shades for different models and the description of the prototype and specifications is listed below:

i. gray: The shades of gray ranges between 0 (black) and 1 (white). For example, 0.89 will be very light gray, and 0.20 will be the dark gray. The command defined for the light gray will be:

ii. rgb: It defines the three colors, namely, red, green, and blue. The range is the same between 0 and 1. The command is written as:

iii. RGB: In this prototype, the quantity is represented with the number between 0 and 255 of each color. The command is written as:

iv. HTML: These are the six hexadecimal numbers written in the format of RRGGBB. The format is similar to that used in HTML. The command for html is written as:

v. cmyk: It stands for cyan, magenta, yellow, and black. The quantity of color is represented between 0 and 1. The command is written as:

The code for color mixing commands is given below:

Output:

You can note the difference between the new colors and the percentage distributions to the colors.

Latex Colors

The code for prototype commands is given below:

Output:

Latex Colors

You can also insert two or more colors in a single line. The code for such type is given below:

Output:

Latex Colors

Text Highlight

There are commands used to highlight the text. You can choose any color to highlight your text, depending on your requirements. You need a soul package with the xcolor package to implement the highlighted text.

The soul package is written as \usepackage{soul}

The command to highlight the text is written as \hl{ any text}. Here 'hl' command is used as highlight caption.

The simple code to highlight the text is given below:

You can see in the above example, we have used the bold command, color, and the highlight command.

The output is shown in the below image:

Latex Colors

To specify the color highlight, you need to use the \sethlcolor{color name} command. You can also use many color highlights in a single program.

The code for the color highlight is given below:

Output:

Latex Colors

Text Background

You can change the text background color as well as the frame/boundary color of that background using the \fcolorbox{any color for frame}{any background color}{text} command. The text background can be changed using the \colorbox{anycolor}{text} command.

To change the text background, the code is given below:

Output:

Latex Colors

To change the text background and the frame, the code is given below:

Output:

Latex Colors

Page Background color

You can change the background color of a page using the \pagecolor{color name} command. The code to change the color of background is given below:

Here, we have chosen the light gray color. You can change the color according to your requirements.

Output:

Latex Colors

Let's the color be orange now. The output will be:

Latex Colors

If you choose the pink color, then the output will be:

Latex Colors

Colored Lines

You can draw the colored lines anywhere in your document. The width of a line can be set according to the requirements. The code is given below:

The colored lines of \LaTeX are given below: \\

Here, we have first created the colors and then used further to draw colored lines.

Output:

Latex Colors
Next TopicLatex Images




Help Others, Please Share

facebook twitter google plus pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA