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

1 Answer 1

15

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

4
  • Ah, this is what he meant? :|
    – Alenanno
    May 25, 2016 at 15:07
  • Yes, this is what I meant. However, I tried this and for some reason it works for 2 parameters but not for 3. May 25, 2016 at 15:16
  • @AitorPérezPérez See the update
    – percusse
    May 25, 2016 at 15:20
  • Yes, that works. I changed the 2 to a 3, but I did not write "n args={3}", I don't know why "2 args" works but "3 args" does not. Thank you very much! May 25, 2016 at 15:25

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .