# Colored box around enumerate labels

I want a colored box around enumerate labels. My actual code is this:

\documentclass{article}

\usepackage{tikz}
\usepackage{enumitem}

\newcommand{\fff}[1]{\tikz
\node[
inner sep=1.5pt,
draw=blue,
fill=blue,
text=black,
rounded corners=2pt]{#1};}

\begin{document}
\begin{enumerate}[label=\fff{\Alph*.}]
\item text
\end{enumerate}

\fff{A.}
\end{document}


As you can see this code does not work. However the \fff command works if not used inside the label specification.

Does anyone knows what is wrong with this code?

-
Welcome to TeX.SX! You can have a look at our starter guide to familiarize yourself further with our format. – texenthusiast Aug 10 '13 at 15:53

The value of label in the enumitem package is a moving argument, so you need to \protect your command (I also changed the baseline):

\documentclass{article}

\usepackage{tikz}
\usepackage{enumitem}

\newcommand{\fff}[1]{\tikz[baseline=-0.65ex]
\node[
inner sep=1.5pt,
draw=blue,
fill=blue,
text=black,
rounded corners=2pt]{#1};}

\begin{document}
\begin{enumerate}[label=\protect\fff{\Alph*.}]
\item text
\end{enumerate}

\fff{A.}
\end{document}


Another options is to declare the command as robust from the beginning, so you don't have to \protect it every time is used in a moving argument:

\documentclass{article}

\usepackage{tikz}
\usepackage{enumitem}

\DeclareRobustCommand{\fff}[1]{\tikz[baseline=-0.65ex]
\node[
inner sep=1.5pt,
draw=blue,
fill=blue,
text=black,
rounded corners=2pt]{#1};}

\begin{document}
\begin{enumerate}[label=\fff{\Alph*.}]
\item text
\end{enumerate}

\fff{A.}
\end{document}

-
amazing! Thanks! – sara s Aug 10 '13 at 15:53
@saras You're welcome! Dont't forget that you can accept the answer by clicking the checkmark to its left :-) In case of doubt, please see How do you accept an answer?. – Gonzalo Medina Aug 10 '13 at 15:54
I will in 4 minutes ;) – sara s Aug 10 '13 at 15:57
@saras thanks :-) – Gonzalo Medina Aug 10 '13 at 16:01
@sars I added another possible solution to my updated answer. – Gonzalo Medina Aug 10 '13 at 16:17