2

The following code gives one good solution for displaying numbers in cricle but it would be better to have the possibility to control the size of the circle. Why ? In the example below you will see that the three numbers in circle do not look pretty when they are ine the same context : in the same paragraph or in one list like in the following code.

So I would like to us the first optional argument so as to do the following things :

  1. If the first optional argument is 0, then the diameter of the circle is the current automatic one.
  2. If the first optional argument is one natural number n <> 0, then the diameter of the circle is n times one character width.
  3. In other case, one error must be raised.

Here is the code to modify...

% Source : http://tex.stackexchange.com/questions/7032/good-way-to-make-pgftextcircled-numbers

\documentclass{article}
    \usepackage{enumitem}
    \usepackage{tikz}

    \newcommand{\pgftextcircled}[2][0]{
        \setbox0=\hbox{#2}%
        \dimen0\wd0%
        \divide\dimen0 by 2%
        \begin{tikzpicture}[baseline=(a.base)]%
            \useasboundingbox (-\the\dimen0,0pt) rectangle (\the\dimen0,1pt);
            \node[
                circle,
                draw,
                outer sep=0pt,
                inner sep=0.1ex
            ] (a) {#2};
        \end{tikzpicture}
    }

\begin{document}

\begin{description}
    \item[Automatic width :] \pgftextcircled{0} , \pgftextcircled{63} , \pgftextcircled{733}
    \item[Width = 2 :]       \pgftextcircled[2]{0} , \pgftextcircled[2]{63} , \pgftextcircled[2]{733}
    \item[Width = 3 :]       \pgftextcircled[3]{0} , \pgftextcircled[3]{63} , \pgftextcircled[3]{733}
\end{description}

Lets' try in one list :

\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}
projetmbc
  • 13,315

1 Answers1

2

Try this, for example:

\documentclass{article}
\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{description}
    \item[Automatic width :] \pgftextcircled{1} , \pgftextcircled{63} , \pgftextcircled{733}
    \item[Width = 2 :]       \pgftextcircled[2]{0} , \pgftextcircled[2]{63} , \pgftextcircled[2]{733}
    \item[Width = 3 :]       \pgftextcircled[3]{0} , \pgftextcircled[3]{63} , \pgftextcircled[3]{733}
\end{description}

\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}
unbonpetit
  • 6,190
  • 1
  • 20
  • 26
  • Thanks a lot ! \wd\nodebox\dimexpr\wd\nodebox*#1 redefines \wd\nodebox to be equal to \dimexpr\wd\nodebox*#1. Isn't it ? One secund question. hbox to \wd\nodebox{\hss#2\hss} defines one box of width \wd\nodebox and content \hss#2\hss where \hss helps to centralize the text. Isn' it ? – projetmbc Nov 05 '11 at 14:23