Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I have a custom shape defined using TikZ. This shape has an optional part; if this is to be drawn, the colour has to be specified.

So I'd like to be able to use the following syntax:

\node [MyShape] at (0,0) {}; % Draw the shape without the optional part
\node [MyShape, mycolour=blue] at (0,1) {}; % Draw the shape with the optional part in blue

I know how to use boolean keys to turn options on and off. I know how to use keys to pass colour parameters. But here I need to do both at once!

share|improve this question
Try \tikzset{/tikz/set and colour/.style={mycolour=#1,draw the optional part=true}} –  Loop Space Sep 24 '12 at 13:28
(Without a MWE it's hard to test to see if that's what you really want to do, hence posting as a comment rather than an answer.) –  Loop Space Sep 24 '12 at 13:29
I want to be able to use exactly the example syntax provided in the question. The second example line should set a boolean variable to 'true', and store the colour that has been provided. –  Jamie Vicary Sep 24 '12 at 13:35
If you tell us exactly how the drawing and colouring are to be done, it'll be easier to give a precise answer. As it is, the best we can do is give vague hints. –  Loop Space Sep 24 '12 at 13:41
Jake's comment gives me exactly what I need. –  Jamie Vicary Sep 24 '12 at 13:56

1 Answer 1

Amalgamating the comments, it seems that you want to use pgfkeys' notion of styles. These can take arguments, so:

         colour of optional part=#1,
         draw the optional part=true

means that calling mycolour=blue sets both the colour of the optional part (assuming that is what /tikz/colour of optional part=<colour> does) and the flag to draw it (assuming that is what /tikz/draw the optional part controls).

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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