1

I would like to color bullets in my lists (for example, to signify tasks that are done or not/hard or easy, etc.), including in nested lists.

I found this and successfully used it. Since I would like to color different bullets in the same list in different colors, I used the \def function to define a few shortcuts, and it works in the code below, but the way the nested lists turn out is not ideal.

\documentclass{article}

\usepackage{color}

\def\itemr{\item[\textcolor{red}{\textbullet}]}
\def\itemg{\item[\textcolor{green}{\textbullet}]}

\begin{document}

\section*{Hey!}

\begin{itemize}
   \item Now we test the colors
   \itemr This one should be in red
   \itemg This one green
   \itemg Only the bullets themselves are colored, which is the goal
   \begin{itemize}
         \item Now notice what happens when I color the nested list bullets too
         \item While the uncolored are dashes
         \itemr The colored ones are level 1 bullets again
         \itemr While I would like them to be colored dashes
   \end{itemize}
\end{itemize}
\end{document}

Compiled in Overleaf

I know why this is so - \textbullet refers to the specific type of bullet. I know I can define different shortcuts for different levels. The question is if there is a master code for "the default bullet label in this level, whatever level we're on" that I can use instead of \textbullet, so that I don't have to think each time at what level I am (might have four levels of nesting, maybe more).

I would also appreciate any other way to do what I'm asking so long as it does not involve a lot of hassle on the flow.

Thanks in advance!

1 Answer 1

1

Here are the definitions of the labels that are set at each level within an itemize. They have the form \labelitem<level>, where <level> is a roman numeral (taken from article.cls):

\newcommand\labelitemi  {\labelitemfont \textbullet}
\newcommand\labelitemii {\labelitemfont \bfseries \textendash}
\newcommand\labelitemiii{\labelitemfont \textasteriskcentered}
\newcommand\labelitemiv{ \labelitemfont \textperiodcentered}
\newcommand\labelitemfont{\normalfont}

You can tap into/update \labelitemfont to be the colour you're interested in and then just set the item as per usual in the following way:

\def\itemr{{\renewcommand{\labelitemfont}{\color{red}}\item\leavevmode\ignorespaces}}
\def\itemg{{\renewcommand{\labelitemfont}{\color{green}}\item\leavevmode\ignorespaces}}

Or, even easier:

\def\itemr{{\color{red}\item\leavevmode\ignorespaces}}
\def\itemg{{\color{green}\item\leavevmode\ignorespaces}}

Both of the above doesn't use the optional argument associated with \item and therefore sets the label at that level.

enter image description here

\documentclass{article}

\usepackage{xcolor}

\def\itemr{{\color{red}\item\leavevmode\ignorespaces}}
\def\itemg{{\color{green}\item\leavevmode\ignorespaces}}

\begin{document}

\section*{Hey!}

\begin{itemize}
  \item Now we test the colors
  \itemr This one should be in red
  \itemg This one green
  \itemg Only the bullets themselves are colored, which is the goal
  \begin{itemize}
    \item Now notice what happens when I color the nested list bullets too
    \item While the uncolored are dashes
    \itemr The colored ones are level 1 bullets again
    \itemr While I would like them to be colored dashes
  \end{itemize}
\end{itemize}

\end{document}
2
  • 1
    @OphirAverbuch: Your request now makes much more sense. I've updated my answer to accommodate for that.
    – Werner
    Feb 18, 2021 at 18:04
  • That's it, Thanks! Feb 19, 2021 at 20:15

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .