# newcommand with argument produces unwanted extra space within tikzpicture

I am creating some pictures I want to use within nodes. When I use a \newcommand with an argument, extra space is added and I can't get rid of it.

\documentclass{article}
\usepackage{tikz}
\begin{document}

\newcommand{\foo}[1][3]{
\begin{tikzpicture}
\foreach \x in {0,1,...,#1}
\filldraw (\x,0) circle (0.2cm);
\end{tikzpicture}
}

\newcommand{\test}{
\begin{tikzpicture}
\foreach \x in {0,1,...,3}
\filldraw (\x,0) circle (0.2cm);
\end{tikzpicture}
}

\begin{tikzpicture}
\node at(0,0)    [draw, rectangle, inner sep=0] {\foo};
\node at(0,-0.5) [draw, rectangle, inner sep=0] {\test};
\end{tikzpicture}
\end{document}

-
I don't know tikz, but most likely it is the ends of lines, put a % at the end of every line in your \newcommand your current definition has 5 space tokens coming from the ends of line. –  David Carlisle Mar 29 '12 at 12:53

Remove spurious blank spaces:

\newcommand{\foo}[1][3]{%
\begin{tikzpicture}
\foreach \x in {0,1,...,#1}
\filldraw (\x,0) circle (0.2cm);
\end{tikzpicture}%
}

\newcommand{\test}{%
\begin{tikzpicture}
\foreach \x in {0,1,...,3}
\filldraw (\x,0) circle (0.2cm);
\end{tikzpicture}%
}

-
Awesome! Thanks for the fast reply! –  Markus Grün Mar 29 '12 at 13:12