8

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?

0

1 Answer 1

12

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}

enter image description here

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}
0

You must log in to answer this question.

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