[Tex/LaTex] Setting global tikz options directly vs. inside the ‘every picture’ style

tikz-pgftikz-styles

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?

Best Answer

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.

Related Question