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

I tried this and it works:

        \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:

        \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.


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.

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

enter image description here

  • Ah, this is what he meant? :|
    – Alenanno
    May 25 '16 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 '16 at 15:16
  • @AitorPérezPérez See the update
    – percusse
    May 25 '16 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 '16 at 15:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.