5

I'm trying to make an enumerate list that has the numbers inside a colored circle. For the circles I'm using the tikz package and the color package. I define a circle in the preamble and then I redefine the list items:

\documentclass{report}

\usepackage{color}
\usepackage{tikz}

% Defining the circle:
\newcommand*\circled[1]{\tikz[baseline=(char.base)]{
    \node[shape=circle,draw,inner sep=2pt,fill=lightgray,lightgray] (char) {\color{gray}\textbf#1};}}

% Redefining the list items
\renewcommand{\labelenumi}{\protect\circled{enumi}}

\begin{document}

\begin{enumerate}
 \item foo
 \item bar
\end{enumerate}

\end{document}

The problem is that instead of printing the list numbers, it just prints an enumi. I'm following the Wikibooks on customizing enumerated lists. I think there should be a way to make it work without adding extra packages, but I don't know how.

If it is not through enumi, how should I access the number of the list?

Cheers!

  • 1
    Maybe \protect\circled{\arabic{enumi}} works? – egreg Oct 1 '14 at 22:00
  • @egreg Oh, so it was the \arabic! It worked =). However I'm getting a warning: ** WARNING ** Unable to read OpenType/TrueType Unicode cmap table. and ** WARNING ** Failed to load ToUnicode CMap for font "Alegreya-Black" – Xirux Nefer Oct 1 '14 at 22:03
  • I see no such warning if I add \usepackage{Alegreya}. Your example shows no trace of using that font, so I can't say more. But it's certainly not connected with the present problem. – egreg Oct 1 '14 at 22:13
  • @egreg Oh my, you're right. Sorry! (it's past midnight and I'm a bit tired, he he) – Xirux Nefer Oct 1 '14 at 22:15
6

You should not say \textbf#1, but \bfseries#1 or \textbf{#1}. Also it should be \arabic{enumi}, not enumi: with your code you're passing enumi to \circled as #1, not the instruction that prints the value of the counter.

However I suggest using enumitem:

\documentclass{report}

\usepackage{color}
\usepackage{tikz}
\usepackage{enumitem}

% Defining the circle:
\DeclareRobustCommand*\circled[1]{%
  \tikz[
    baseline=(char.base)
  ]{%
    \node[
      shape=circle,
      draw,
      inner sep=2pt,
      fill=lightgray,
      lightgray
     ] (char) {\color{gray}\bfseries#1};%
   }%
}

\begin{document}

\begin{enumerate}[label=\circled{\arabic*},ref=\arabic*]
 \item foo
 \item bar
\end{enumerate}

\end{document}

You can customize all first level enumerate environments to use \circled with

\setlist[enumerate,1]{label=\circled{\arabic*},ref=\arabic*}

in the preamble and you'll need no optional argument to \begin{enumerate}.

enter image description here

If you don't want extra packages, but I'm not sure why, then the method of redefining \labelenumi will work, provided it is

\renewcommand{\labelenumi}{\protect\circled{\arabic{enumi}}}

However remember that in the definition of \circled you must do either \bfseries#1 or \textbf{#1}, because \textbf#1 is wrong and will produce unscrutable errors.

Why should you want to load enumitem? Simple; if you do

\item\label{foo} text

and then try \ref{foo}, you'll get a circled number in text, which doesn't appear correct. With the code above using enumitem, \ref{foo} will just print an unadorned number.

  • Mmm... Your first comment had solved the problem already. I just had to add the \arabic. I prefer to avoid adding an extra package if I can achieve things natively. I'll accept the answer though. The colors are just easy ones, for the sake of testing. The document already has a defined palette and design =) Thank you! – Xirux Nefer Oct 1 '14 at 22:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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