# Getting numbers to appear in circles

I have a linked question that I previously found on here, but I cannot make any comment yet to post. The link being: Good way to make \textcircled numbers?

My question was how could we use this command more then once in our TeX file in different parts of our file without generating an error.

Example Code:

\documentclass{article}
\usepackage{tikz}
\newcommand*\circled[1]{\tikz[baseline=(char.base)]{
\node[shape=circle,draw,inner sep=2pt] (char) {#1};}}
\begin{document}
Numbers aligned with the text:  \circled{1} \circled{2} \circled{3} end.
\end{document}


The error message is this:

! LaTeX Error: Command \circled already defined.
Or name \end... illegal, see p.192 of the manual.
See the LaTeX manual or LaTeX Companion for explanation.
Type H <return> for immediate help.
...

1.222 ...circle,draw,inner sep=2pt] (char) {#1};}}


When removing the \newcommand* it shows this next error message:

! You can't use 'macro parameter character #' in restricted horizontal mode.
<argument> ...ircle,draw,inner sep=2pt] (char {##
1}


Can someone help out please. Thank You so much.

-
Are you getting those error messages with the exact code you posted? I ask you because that code compiles OK in my system. –  Gonzalo Medina Apr 8 '11 at 17:49
Like @Gonzalo already said: The above example code compiles fine. You seem to define \circled multiple times, instead of using it. Make sure that you only have one \newcommand and that it isn't inside a macro you use. –  Martin Scharrer Apr 8 '11 at 17:53
Also: welcome to TeX.SX! A tip: you can use backticks  to format inline code or package names, like I did in my edit. We also prefer to not have any opening or closing lines. Thanks. –  Martin Scharrer Apr 8 '11 at 17:59
Yea, i used that entire code in two separate locations with the new command in each of them in the TeX file. I just want to put the circle somewhere different in the file without saying it is used multiple times. Thanks, for the warm welcome. –  night owl Apr 8 '11 at 18:01
@night owl. I quote: "I used that entire code in two separate locations with the new command in each of them in the teX file." That is definitely not what you should do (unless I misunderstand what you mean). You just need one single definition in the preamble. You also just need one preamble. Does the code snipplet you quoted by itself compile fine for you? If so, search your TeX file for duplicate definitions of \circled. –  Willie Wong Apr 8 '11 at 18:15

As is mentioned in the comments, your example code compiles fine, but you mustn't use the \newcommand*\circled more than once. If you want more circled numbers, just use \circled{n} for each instance of a circled n.

My guess is that you did the following: You tried some code like

\documentclass{article}
\usepackage{tikz}
\newcommand*\circled[1]{\tikz[baseline=(char.base)]{
\node[shape=circle,draw,inner sep=2pt] (char) {#1};}}
\begin{document}
Numbers aligned with the text:  \circled{1} \circled{2} \circled{3} end.
\newcommand*\circled[1]{\tikz[baseline=(char.base)]{
\node[shape=circle,draw,inner sep=2pt] (char) {#1};}}
Numbers aligned with the text:  \circled{1} \circled{2} \circled{3} end.
\end{document}


and got ! LaTeX Error: Command \circled already defined. This is expected behaviour; you should define \circled only once in the preamble. Then you tried removing the second \newcommand*, but you only removed that. Then indeed you get the error message

! You can't use macro parameter character #' in restricted horizontal mode.


What you have to do is remove the full two lines of the definition, i.e., the lines

\newcommand*\circled[1]{\tikz[baseline=(char.base)]{
\node[shape=circle,draw,inner sep=2pt] (char) {#1};}}

-