# TikZ node newcommand : pass color as argument

I need to create a row of circles (colored markers) followed by some text. See the image below.

I achieve this using the following code.

\begin{tikzpicture}[scale=2]
\matrix[nodes={minimum width=0.05cm, minimum height=0.05cm},
row sep=0.001cm, column sep=0.1cm] {
\node[circle, fill=red ] {}; &
\node[circle, fill=blue ] {}; &
\node[circle, fill=green ] {}; &
\node[circle, fill=orange ] {}; &
\node[circle, fill=pink ] {}; &
\node[draw=none, fill=none, text width=4cm]{Some Text};\\};
\end{tikzpicture}


Since I need to produce this output repetitively, I thought of defining a new command with the code above. Here's the command I defined.

\newcommand{\MarkersAndText}{6}{
\begin{tikzpicture}[scale=2]
\matrix[nodes={minimum width=0.05cm, minimum height=0.05cm},
row sep=0.001cm, column sep=0.1cm] {
\node[circle, fill=#1] {}; &
\node[circle, fill=#2] {}; &
\node[circle, fill=#3] {}; &
\node[circle, fill=#4] {}; &
\node[circle, fill=#5] {}; &
\node[draw=none, fill=none, text width=4cm]{#6};\\};
\end{tikzpicture}


However, I get the following error,

Illegal parameter number in definition of \tikz@temp. <to be read again> 1 l.19 \node[circle, fill=#1] {}; &


Can anyone help me to understand how I can resolve this problem?

Edit : David Carlisle's answer solves the error above. The compilation produces another error when I use the command \MarkersAndText. The new error is,

Package pgf Error: Single ampersand used with wrong catcode

The error is fixed by changing the code block as,

\matrix[nodes={minimum width=0.05cm, minimum height=0.05cm}, row sep=0.001cm, column sep=0.1cm, ampersand replacement=\&] { \node[circle, fill=#1] {}; \&

I am curious as to why the code without ampersand replacement works when outside \newcommand.

• I hope this question helps your curiosity: tex.stackexchange.com/questions/1111/… – Ignasi Sep 3 '15 at 13:42
• Thank you for the link. I have a follow up question with the above setup but for a slightly different problem should I edit the question here? or ask a new question? – rajvi Sep 3 '15 at 17:56
• I think it is better to make a new question with a link to this one. If you edit this one, David's answer won't fit it. – Ignasi Sep 4 '15 at 10:31

\newcommand{\MarkersAndText}{6}

\newcommand{\MarkersAndText}[6]

As it was you were defining \MarkersAndText to be 6