12

I want to pass more than one argument to a pic defined with \tikzset.

I tried this and it works:

\tikzset{
    Piece/.pic={
        \draw (0:1) -- (120:1) -- (240:1) -- cycle;
        \draw (0,0) node {$\Gamma_#1$};
    }
};

\pic {Piece={k}};

I get the following image:

Triangle with one subscript

But what I really need is to have two subscripts, as in this one:

Triangle with two subscripts

However, no matter what I write in the \pic command, it is treated as a string and associated to the #1 argument. I would like something like:

\tikzset{
    Piece/.pic={
        \draw (0:1) -- (120:1) -- (240:1) -- cycle;
        \draw (0,0) node {$\Gamma_{#1,#2}$};
    }
};

\pic {Piece={k,r}};

But this does not work.

How can I specify two different and independent arguments?

Thank you in advance.

1 Answers1

17

You can switch to the alternative definition of the pic style family such that style 2 args or style n args, style args stuff from the regular pgfkeys syntax can be used for arguments.

\documentclass[tikz]{standalone}
\tikzset{
  pics/Piece/.style n args={3}{
    code = { %
          \draw (0:1) -- (120:1) -- (240:1) -- cycle;
          \draw (0,0) node[#2,#3] {$\Gamma_{#1}$};
    }
  }
}
\begin{document}
\begin{tikzpicture}
\pic {Piece={k}{draw=red}{fill=red!10}};
\end{tikzpicture}
\end{document}

enter image description here

percusse
  • 157,807