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.
