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.

The following code gives one way to use circled numbers in one list. For the moment this solution uses one parameter given by the user which is the "width" of the total number of items of the list.

% Sources :
%   1) http://tex.stackexchange.com/questions/7032/good-way-to-make-pgftextcircled-numbers
%   2) http://tex.stackexchange.com/questions/33738/customize-diameter-of-a-circle-around-numbers/33744#33744

\documentclass{article}
    \usepackage[utf8x]{inputenc}
    \usepackage{enumitem}
    \usepackage{tikz}

    \newbox\nodebox
    \newcommand\pgftextcircled[2][0]{%
        \ifnum#1=0%
            \setbox\nodebox\hbox{#2}%
        \else%
            \setbox\nodebox\hbox{0}\wd\nodebox\dimexpr\wd\nodebox*#1\relax
        \fi
        \begin{tikzpicture}[baseline=(a.base)]%
            \node[
                draw,circle,
                outer sep=0pt,
                inner sep=0.5pt
            ](a){\hbox to \wd\nodebox{\hss#2\hss}};
        \end{tikzpicture}%
    }


\begin{document}

\begin{enumerate}[label=\protect{\pgftextcircled[1]{\arabic*}}]
    \item Item n°1
    \item Item n°2
    \item Item n°3
    \item Item n°4
    \item Item n°5
    \item Item n°6
    \item Item n°7
    \item Item n°8
\end{enumerate}

\begin{enumerate}[label=\protect{\pgftextcircled[2]{\arabic*}}]
    \item Item n°1
    \item Item n°2
    \item Item n°3
    \item Item n°4
    \item Item n°5
    \item Item n°6
    \item Item n°7
    \item Item n°8
    \item Item n°9
    \item Item n°10
    \item Item n°11
    \item Item n°12
\end{enumerate}

\end{document}

Could it be possible to define one environment enumerateCircle which knows automatically the length of the list so as to use the following syntax ?

\begin{enumerateCircle}
    \item Item n°1
    \item Item n°2
    \item Item n°3
    \item Item n°4
    \item Item n°5
    \item Item n°6
    \item Item n°7
    \item Item n°8
\end{enumerateCircle}

\begin{enumerateCircle}
    \item Item n°1
    \item Item n°2
    \item Item n°3
    \item Item n°4
    \item Item n°5
    \item Item n°6
    \item Item n°7
    \item Item n°8
    \item Item n°9
    \item Item n°10
    \item Item n°11
    \item Item n°12
\end{enumerateCircle}
share|improve this question
1  
You could write the width to the .aux file and reuse it in the next run. –  Martin Scharrer Nov 5 '11 at 14:44
1  
I'm not one LaTeX expert... How can I do to store this information in the .aux file and how can I reuse it ? –  projetmbc Nov 5 '11 at 15:06
    
Yeah, I can't see a way of doing this in one run. Otherwise \value{enumi} is the value of the counter to use I think. –  qubyte Nov 5 '11 at 15:13
    
If several compilations are needed, this is not a problem. –  projetmbc Nov 5 '11 at 15:19

2 Answers 2

up vote 2 down vote accepted

You can compile the environment just to get the total number of items; this is a job for environ, with a redefinition of \pgftextcircled that takes as optional argument what size you want to encompass:

\documentclass{article}
    \usepackage[utf8]{inputenc}
    \usepackage{enumitem,environ}
    \usepackage{tikz}

\newbox\nodebox
\newcommand\pgftextcircled[2][0]{%
  \sbox\nodebox{#1}%
  \begin{tikzpicture}[baseline=(a.base)]
    \node[
          draw,circle,
          outer sep=0pt,
          inner sep=0.5pt
         ](a){\hbox to \wd\nodebox{\hss#2\hss}};
        \end{tikzpicture}%
    }

\makeatletter
\NewEnviron{enumerateCircle}
  {\setbox0=\vbox{
              \enumerate
                \BODY
                \global\chardef\enCir@final\value{\@enumctr}%
              \endenumerate}%
   \enumerate[label={\pgftextcircled[\number\enCir@final]{\arabic*}}]
     \BODY
   \endenumerate}
\makeatother

\begin{document}

\begin{enumerateCircle}
    \item Item n°1
    \item Item n°2
    \item Item n°3
    \item Item n°4
    \item Item n°5
    \item Item n°6
    \item Item n°7
    \item Item n°8
\end{enumerateCircle}

\begin{enumerateCircle}
    \item Item n°1
    \item Item n°2
    \item Item n°3
    \item Item n°4
    \item Item n°5
    \item Item n°6
    \item Item n°7
    \item Item n°8
    \item Item n°9
    \item Item n°10
    \item Item n°11
    \item Item n°12
\end{enumerateCircle}

\end{document}
share|improve this answer
    
Thanks for this shorter code even if it seems a little slower than the preceding one. –  projetmbc Nov 5 '11 at 17:38
    
@projetmbc Yes, it is slower because it has to typeset the environment twice. But it's this way or adding a self-generated \label command in order to use the information at the next run. –  egreg Nov 5 '11 at 17:44

This shold be what you are looking for:

\documentclass{article}
\usepackage{enumitem}
\usepackage{tikz}
\makeatletter
\newcount\item@cnt
\newcommand*\circle@arg[1]{%
    \tikzpicture[baseline=(a.base)]%
        \node[draw,circle,outer sep=0pt,inner sep=0.5pt](a){\hbox to\max@wd{\hss#1\hss}};
    \endtikzpicture}

\long\def\get@body#1\end{%
    \expandafter\def\expandafter\collected@body\expandafter{\collected@body#1}\find@end}

\newcommand\find@end[1]{%
    \def\temp@name{#1}%
    \ifx\temp@name\name@env
        \count@item
        \setbox\z@\hbox{\item@number}\edef\max@wd{\the\wd\z@}%
        \begin{enumerate}[label=\protect\circle@arg{\arabic*}]
            \collected@body
        \end{enumerate}
    \else
        \expandafter\def\expandafter\collected@body\expandafter{\collected@body\end{#1}}%
        \expandafter\get@body
    \fi}

\newenvironment{enumcircle}
    {\expandafter\endgroup\expandafter\def\expandafter\name@env\expandafter{\@currenvir}%
    \let\collected@body\@empty\get@body}
    \relax

\long\def\count@item@i#1\item{\expandafter\ifx\@car#1\@nil\count@item\else\advance\item@cnt\@ne\expandafter\item\fi}

\long\def\count@item{%
    \begingroup
        \let\item\count@item@i
        \collected@body\item\count@item\item
    \expandafter\endgroup
    \expandafter\def\expandafter\item@number\expandafter{\number\item@cnt}}

\makeatother
\begin{document}
\begin{enumcircle}
    \item Item n°1
    \item Item n°2
    \item Item n°3
    \item Item n°4
    \item Item n°5
    \item Item n°6
    \item Item n°7
    \item Item n°8
\end{enumcircle}

\begin{enumcircle}
    \item Item n°1
    \item Item n°2
    \item Item n°3
    \item Item n°4
    \item Item n°5
    \item Item n°6
    \item Item n°7
    \item Item n°8
    \item Item n°9
    \item Item n°10
    \item Item n°11
    \item Item n°12
\end{enumcircle}
\end{document}
share|improve this answer
    
Thanks. Your solution seems to be a litlle quicker than the following one but the code just after seems to be simpler to understand (I can't tkae time for analyse it for the moment). –  projetmbc Nov 5 '11 at 17:37

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.