Text FormattingUsing color in the label in the listing environment

Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
Post Reply
lances
Posts: 2
Joined: Thu Jun 25, 2009 2:51 am

Using color in the label in the listing environment

Post by lances »

Greetings,

Suppose I have a following list:

\begin{enumerate}
\item ABC
\item DEF
\item GHI
\end{enumerate}

The output is

1. ABC
2. DEF
3. GHI

Now I would like to have these labels (1,2,3) colored in blue, for example, while keeping the color of the text (ABC, DEF, GHI) as it is. How can I do it? Please advise.

1. ABC
2. DEF
3. GHI

Best regards,

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

User avatar
frabjous
Posts: 2064
Joined: Fri Mar 06, 2009 12:20 am

Using color in the label in the listing environment

Post by frabjous »

You should be able to do that with a combination of the xcolor and enumitem packages. E.g.:

Code: Select all

Code, edit and compile here:
\documentclass{article}
\usepackage{xcolor}
\usepackage{enumitem}
\begin{document}
\begin{enumerate}[label=\textcolor{blue}{\arabic*.}]
\item ABC
\item DEF
\item GHI
\end{enumerate}
\end{document}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
lances
Posts: 2
Joined: Thu Jun 25, 2009 2:51 am

Re: Using color in the label in the listing environment

Post by lances »

Is it possible to do this without using enumitem package?
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Using color in the label in the listing environment

Post by localghost »

lances wrote:Is it possible to do this without using enumitem package?
Using this package is the most easiest solution. I wonder about the reason that makes you oppose.


Best regards and welcome to the board
Thorsten
User avatar
Juanjo
Posts: 657
Joined: Sat Jan 27, 2007 12:46 am

Using color in the label in the listing environment

Post by Juanjo »

The following code works without enumitem:

Code: Select all

Code, edit and compile here:
\documentclass{article}
\usepackage{color} % or xcolor, as you like
\begin{document}
\begin{enumerate}
\renewcommand{\labelenumi}{\textcolor{blue}{\arabic{enumi}.}}
\item ABC
\item DEF
\item GHI
\end{enumerate}
\end{document}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
If the list is nested in one or more enumerate environments, you should replace the enumi suffix in \labelenumi and enumi by enumii, enumiii or enumiv, depending on the nesting level. This nuisance can be avoided by using enumitem, since this package takes care automatically of the nesting level.
The CTAN lion is an artwork by Duane Bibby. Courtesy of www.ctan.org.
scolque
Posts: 1
Joined: Thu Oct 22, 2020 4:44 am

Using color in the label in the listing environment

Post by scolque »

Hey, many thanks for your answer. GOD bless you.
Post Reply