The TikZ & PGF manual for version 3.0.1a states in the description of the /tikz/every picture style on p. 125:

you should not use \tikzset to set options directly. For instance, if you want to use a line width of 1pt by default, do not try to say \tikzset{line width=1pt} at the beginning of your document. This will not work since the line width is changed in many places. Instead, say

\tikzset{every picture/.style={line width=1pt}}

This will have the desired effect.

Why does the fact that the line width is changed in many places affect the direct option, but not the same option inside a style?

  • 1
    every picture is pretty much like \AtBeginDocument except that document is replaced by tikzpicture. So the question is pretty much like whether we should put some macro in the preamble or in \AtBeginDocument. And the general answer is that once you know how macros overwrite each others you will know the correct order. – Symbol 1 Jul 3 '17 at 8:44
  • @Symbol1: I'm afraid I'm rather a noob, and am not familiar with \AtBeginDocument and what its advantages are to defining macros in the preamble. Could you please elaborate? – Evan Aad Jul 3 '17 at 8:56

TikZ sets up a default argument set at the start of each picture. It takes the advantage of TeX behavior of nothing is deleted but only overwritten.

Hence when setting up the TikZ pictureit also sets line width, default color etc. while towards the end of the initialization it executes every ... keys.

So very roughly it becomes

\tikzset{ line width = 0.3 pt,
          line join = miter, 
          every picture, 
          every path,
          every node
          every label

(I'm just guessing the order I didn't check at all).

So there is an order to the every ... keys and if any of them include line width key it will overwrite the previous ones and that's what is mentioned.

But if only set once then it will always be overwritten by many other keys.

  • I'm not sure I get your point. Are you saying that setting a property inside the every picture style has greater priority over setting the same property directly? But if this is what you're saying than what's the purpose of the every picture style? Why not make this style obsolete, and then you can set global properties directly without fear that they'll get overwritten by some every picture style, because this style is no longer supported by TikZ. – Evan Aad Jul 3 '17 at 9:17
  • @EvanAad I think I don't understand your objection. If you don't set them, the defaults survive. If you set something outside the picture then it will be get overwritten in many places because they need to be initialized in order to work properly. – percusse Jul 3 '17 at 9:23
  • Does writing \tikzset{line width=1pt} have any effect? – Evan Aad Jul 3 '17 at 9:31
  • 1
    @EvanAad Yes skipping a few technicalities that is indeed the general situation. It might help to note that every path command starts with the initial default settings and then adds [every path, #1] such that you can still override the generic settings. This is quite a different way of doing things in other languages, say, in Python, you can't use the same keyword twice but in pgfkeys syntax, the last one wins. – percusse Jul 3 '17 at 13:15
  • 1
    @EvanAad That's where things get a bit hairy. If you search this site about pgfkeys questions some of them are actually on this topic. You can filter key families or you can forward certain keys and forbid the others etc. It is really a full fledged key system. \tikzset is only a convenience for skipping the typing of \pgfkeys{/tikz/.cd, ....} everytime. Note for example, pgfplots or pgfplotstable or tcolorbox all have their own partial overwriting of the relevant keys to impose their own choices over TikZ. – percusse Jul 3 '17 at 14:36

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.