# Global set node background

I know I can do this:

\draw (5,0) node[above=3pt,fill=white,inner sep=0pt] {$5$}


But I wonder if it is possible to set the 3pt, fill=white, and inner sep=0pt globally for every node in my document?

Thanks.

-
Let's say I want to offset each node by 3pt. How do I do that? –  David Aug 12 '13 at 20:38

You can use \tikzset in the preamble for global options. A style that is used for every node is called every node. You need to use one of the following handlers to change/add keys to the style:

• .style: overwrites the current definition of the style;
• .append style: appends a set of keys to the current definition;
• .prefix style: prefixes a set of keys to the current definition.

By default, the every node style is empty/undefined when TikZ is loaded so you can actually use all of those keys without a difference.

But just for later reference (you can also alter the every node style at the beginning of a TikZ picture, a scope environment or in a \path, let’s have an example.

Let us assume that the every node style has been defined similar to

\tikzset{every node/.style={draw=green, fill=blue}}


Every node now will have its path drawn in green and filled in blue. A TikZ picture that starts with

\begin{tikzpicture}[every node/.style={shape=circle}]


will be of the shape circle but neither drawn nor filled as the previous style has been overwritten due to the .style handler.

The declarations

\begin{tikzpicture}[every node/.append style={shape=circle}]


and

\begin{tikzpicture}[every node/.prefix style={shape=circle}]


will both result in nodes of a circular shape that has been drawn and filled in green and blue respectively. There is no difference (in the outcome) between .append and .prefix as the keys shape, draw and fill are independent of each other.

A declaration like

\begin{tikzpicture}[every node/.append style={draw=red}]


will change the definition of every node to

draw=green, fill=blue, draw=red


The first draw key is not overwritten per se as it is still executed when a node is created but the second draw key overwrites the changes/settings the previous occurrence made. (In this case, the command \tikz@mode@drawtrue is added twice to \tikz@mode and thus executed twice when TikZ finished the path but this doesn’t affect anything.)

The declaration

\begin{tikzpicture}[every node/.prefix style={fill=red}]


will not result in nodes that are filled with the color red as the definition of every node has changed to

fill=red, draw=green, fill=blue


The latter fill=blue overwrites the changes/settings of fill=red.

Using keys multiple times in styles do usually not have any side effects as they simply set certain settings but their effects can accumulate. For example, the use of xshift=1cm, xshift=2cm will result in a total transformation of 3cm.

-