Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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?

share|improve this question
    
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
add comment

1 Answer 1

up vote 7 down vote accepted

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}
share|improve this answer
    
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
1  
@sars I added another possible solution to my updated answer. –  Gonzalo Medina Aug 10 '13 at 16:17
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.