21

In a command like:

\tikset{qar/.style={draw,rectangle,fill=#1}}

is it possible to add a default key value for the option fill so that if you have:

\node [qar] {};

the node will be filled with the default color (for example, red) while if you have:

\node [qar={blue}] {};

the node will be filled with the selected color?

And what if instead of one there are two arguments like:

\tikset{qar/.style 2 args={draw=#2,rectangle,fill=#1}}

?

28

You can assign a default value for a key by using the .default handler. By setting

qar/.style={
    draw,
    rectangle,
    fill=#1
},
qar/.default=red

the value red will be used whenever qar is called without an argument.

The same thing works for keys that take two or more arguments:

qar2/.style 2 args={
    rectangle,
    draw=#1, thick,
    fill=#2
},
qar2/.default={blue}{yellow}
|improve this answer|||||
  • 7
    How about qar2/.style args= {#1and#2also#3}{ rectangle, draw=#1, thick, fill=#2, text=#3 }, - how do you set default values for that? – Make42 Dec 10 '15 at 15:42
  • @Make42, it seens that qar2/.default={1 and 2 also 3} works... – Rmano May 28 '19 at 8:18
  • Can you also just set defaults partially? So something like: qar2/.style 2 args={ rectangle, draw=#1, thick, fill=#2 }, qar2/.default={blue}{} – gr4nt3d Jun 17 '19 at 22:02

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.