# Making a box completely around a enum item

I want to make grey box around every enumerate item. Therefore I tried the following:

\documentclass{article}
\usepackage[most]{tcolorbox}
\usepackage{enumitem}

\begin{document}

\begin{enumerate}[label=\textbf{{[T\arabic*0]}}]
\begin{tcolorbox}
{\item Item 1 \label{funnyItem}}
\end{tcolorbox}
\begin{tcolorbox}
{\item Item 2 \label{mediocreItem}}
\end{tcolorbox}
\begin{tcolorbox}
\end{tcolorbox}
\end{enumerate}

\end{document}


The problem is, the tcolorbox isn't covering the enumerate number [TXX].

I need the automatic enumerate numbering, because I need to ref to the item and get the number. Like \ref{sadItem} leading to the output [T30]. Any ideas?

• Welcome to TeX.SX! Why don't you use tcbitemize and an own counter? – TeXnician May 25 '18 at 9:45
• Sorry for perhaps sounding lazy, but after looking into the tcolorbox manual, I couldn't get how to provide a own counter, do you perhaps have a minimal example or a link to one? Thanks. – Olli May 25 '18 at 10:08

Quick hack:

\documentclass{article}
\usepackage[most]{tcolorbox}
\usepackage{enumitem}

\tcbset{enlarge left by=-0.8cm,left=1.2cm}

\begin{document}

\begin{enumerate}[label=\textbf{{[T\arabic*0]}}]
\begin{tcolorbox}
{\item Item 1 \label{funnyItem}}
\end{tcolorbox}
\begin{tcolorbox}
{\item Item 2 \label{mediocreItem}}
\end{tcolorbox}
\begin{tcolorbox}
\end{tcolorbox}
\end{enumerate}

\end{document}


• Kind of dirty, but for the moment it works. Thank you. – Olli May 25 '18 at 16:38

I think this is a more a la tcolorbox solution.

Every item is an independent tcolorbox with an auto counter (see init options it tcolorbox documentation). This autocounter can be free styled and used for further reference. The title box is automatically declared as the counter value and is printed in front of tcolorbox contents.

An initially empty optional parameter is used to add possible label values and any other format options.

\documentclass{article}
\usepackage[most]{tcolorbox}

\newtcolorbox[%
auto counter,
number freestyle={[T\noexpand\arabic{\tcbcounter}0]}]
{myitembox}[1][]{%
detach title,
title={\thetcbcounter},
coltitle=black,
fonttitle=\bfseries,
#1}

\begin{document}
\begin{myitembox}[label=a]
This is an item in box~\ref{a}
\end{myitembox}
\begin{myitembox}[label=b]
This is an item similar to box~\ref{a}, but this is box~\ref{b}
\end{myitembox}
\begin{myitembox}[colframe=red, coltitle=green!40!black]
This is an item
\end{myitembox}
\end{document}