How to Assign the Numbers Automatically in This Enumerate Environment

Consider

\documentclass{book}
\usepackage{tcolorbox}

\newtcbox{\blackbox}[1][]{nobeforeafter, notitle, %sharpcorners,
colframe=black,
colback=black,
top=4pt,
left=5pt,
right=5pt,
bottom=2pt,
fontupper=\sffamily\bfseries,
colupper=white,
tcbox raise base,
#1}
\begin{document}
\thispagestyle{empty}
\Large
\begin{enumerate}
\item[\blackbox1] Can the numbers be assigned automatically?
\item[\blackbox2]
\item[\blackbox3]
\end{enumerate}
\end{document}


which produces

Rather than typing \item[\blackbox1], \item[\blackbox2], ..., \item[\blackboxn] for an n-item enumerate delineation, I ask how one may have the numbers within the boxes automatically assigned by Latex; analogous to the way it happens for a standard enumerate environment?

Thank you.

With enumitem package, with \setlist you can change all the lists of your document:

\documentclass{book}
\usepackage{tcolorbox}

\newtcbox{\blackbox}[1][]{nobeforeafter, notitle, %sharpcorners,
colframe=black,
colback=black,
top=4pt,
left=5pt,
right=5pt,
bottom=2pt,
fontupper=\sffamily\bfseries,
colupper=white,
tcbox raise base,
#1}
\usepackage{enumitem}
\setlist{label*={\blackbox{\arabic*}}}
\begin{document}
\thispagestyle{empty}
\Large
\begin{enumerate}
\item Can the numbers be assigned automatically?
\item Another item
\item The third item
\end{enumerate}
\end{document}


Or, in the following way, you can change only one (or some) list of your document:

\documentclass{book}
\usepackage{tcolorbox}

\newtcbox{\blackbox}[1][]{nobeforeafter, notitle, %sharpcorners,
colframe=black,
colback=black,
top=4pt,
left=5pt,
right=5pt,
bottom=2pt,
fontupper=\sffamily\bfseries,
colupper=white,
tcbox raise base,
#1}

\usepackage{enumitem}

\begin{document}
\thispagestyle{empty}\Large

... and if only the following list should be changed but not any list of your document:

\begin{enumerate}[label*={\blackbox{\arabic*}}]
\item Can the numbers be assigned automatically?
\item Another item
\item The third item
\end{enumerate}

Ordinary list:

\begin{enumerate}
\item This is an ordinary list
\item Another item
\item The third item
\end{enumerate}

\end{document}


You may also define your own list, with \newlist, and use it whenever you like. In the following, I created blackboxlist.

\documentclass{book}
\usepackage{tcolorbox}

\newtcbox{\blackbox}[1][]{nobeforeafter, notitle, %sharpcorners,
colframe=black,
colback=black,
top=4pt,
left=5pt,
right=5pt,
bottom=2pt,
fontupper=\sffamily\bfseries,
colupper=white,
tcbox raise base,
#1}

\usepackage{enumitem}
\newlist{blackboxlist}{enumerate}{1}
\setlist[blackboxlist]{label*={\blackbox{\arabic*}}}

\begin{document}
\thispagestyle{empty}\Large

Customized list:

\begin{blackboxlist}
\item Can the numbers be assigned automatically?
\item Another item
\item The third item
\end{blackboxlist}

Ordinary list:

\begin{enumerate}
\item This is an ordinary list
\item Another item
\item The third item
\end{enumerate}

\end{document}


As Mico pointed out, if it's important that the special numbers not protrude into the left-hand margin, you could add the option left=0pt to the argument of \setlist:

\documentclass{book}
\usepackage{tcolorbox}

\newtcbox{\blackbox}[1][]{nobeforeafter, notitle, %sharpcorners,
colframe=black,
colback=black,
top=4pt,
left=5pt,
right=5pt,
bottom=2pt,
fontupper=\sffamily\bfseries,
colupper=white,
tcbox raise base,
#1}

\usepackage{enumitem}
\newlist{blackboxlist}{enumerate}{1}
\setlist[blackboxlist]{label*={\blackbox{\arabic*}},left=0pt}

\usepackage{mwe}% < -- for testing purpose only

\begin{document}
\thispagestyle{empty}\Large

\blindtext% < -- for testing purpose only

\begin{blackboxlist}
\item Can the numbers be assigned automatically?
\item Another item
\item The third item
\end{blackboxlist}

\blindtext% < -- for testing purpose only

\end{document}


• +1. If it's important that the special numbers not protrude into the left-hand margin, one could add the option left=0pt to the argument of \setlist.
– Mico
Oct 18 at 11:55
• @Mico Thank you for pointing that out, I added it to my answer. Oct 18 at 12:11
• Thank you most kindly for these very helpful answers. Oct 18 at 12:11
• @SamuelBowditch You're welcome! And thank you for accepting my answer. Oct 18 at 12:12
• +1. For considering all options, and going the length of adding examples for all of them. Nice one! Oct 18 at 17:28