4

I want an enumerated list where each number must be white circled on a coloured background. The background color must be passed as an option to each item in the list, without excluding color repetitions. The code has to be something like this:

\documentclass[12pt,a4paper]{book}
\usepackage[latin1]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[italian]{babel}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{makeidx}
\usepackage{graphicx}
\usepackage{enumerate}
\begin{document}
    \begin{enumerate}
        \item[color1] Text
        \item[color1] Text
        \item[color2] Text
    \end{enumerate}
\end{document}

2 Answers2

7

Borrowing heavily from my answer here, Enumerate with circles and different colors. The default color, if not specified, is black.

See ADDENDUM to provide two-digit capacity, per OP request.

\documentclass{article}
\usepackage{stackengine,xcolor}
\newcommand\circnum[2]{\stackinset{c}{}{c}{.1ex}{\small\textcolor{white}{#2}}%
  {\abovebaseline[-.7ex]{\Huge\textcolor{#1}{$\bullet$}}}}
\newenvironment{myenum}
{\let\svitem\item
 \renewcommand\item[1][black]{%
   \refstepcounter{enumi}\svitem[\circnum{##1}{\theenumi}]}%
\begin{enumerate}}{\end{enumerate}}
\begin{document}
\begin{myenum}
\item[red] first
\item[blue] next
\item[cyan] third
\item fourth
\item last
\end{myenum}
\end{document}

enter image description here


ADDENDUM

\documentclass{article}
\usepackage{stackengine,xcolor,graphicx}
\newcommand\circnum[2]{\smash{\stackinset{c}{}{c}{.2ex}{\small\textcolor{white}{#2}}%
  {\abovebaseline[-1.43ex]{\Huge\textcolor{#1}{\scalebox{1.5}{$\bullet$}}}}}}
\newenvironment{myenum}
{\let\svitem\item
 \renewcommand\item[1][black]{%
   \refstepcounter{enumi}\svitem[\circnum{##1}{\theenumi}]}%
\begin{enumerate}}{\end{enumerate}}
\begin{document}
\begin{myenum}
\item[red] first
\item[blue] next
\item[cyan] third
\item fourth
\item ...
\item ...
\item ...
\item ...
\item ...
\item ...
\item[purple] last
\end{myenum}
\end{document}

enter image description here

2

The following also builds on Enumerate with circles and different colors, updating the first level of enumerate to use a new \item, where the optional argument specifies the colour. If you don't supply an optional argument, the default configuration is used. This allows you to use the same enumerate environment for a coloured-\item list or not.

enter image description here

\documentclass{article}

\usepackage{stackengine,xcolor,enumitem}

% https://tex.stackexchange.com/a/590844/5764 \newcommand\circnum[1]{\stackinset{c}{}{c}{.1ex}{\small\textcolor{white}{#1}}% {\abovebaseline[-.7ex]{\Huge\textcolor{enumicol}{\textbullet}}}}

\newcommand{\updateitem}{% \let\olditem\item% Store \item in \olditem \renewcommand{\item}[1][]{% % https://tex.stackexchange.com/a/53091/5764 \if\relax\detokenize{##1}\relax % No optional argument supplied to \item \renewcommand{\labelenumi}{\theenumi.}% Default \else \colorlet{enumicol}{##1}% Update current circle label colour \renewcommand{\labelenumi}{\circnum{\theenumi}}% Set label as a circled number \fi \olditem% Call original \item } }

\setlist[enumerate,1]{before=\updateitem}

\begin{document}

\begin{enumerate} \item[red] first \item[green] next \item[blue] third \item[black!50] fourth \item last \end{enumerate}

\end{document}

Werner
  • 603,163