I see here:
How to specify a fill color in RGB format in a node in tikzpicture?
It is possible to change the color of a node locally. However, I would like to add a background color globally to all nodes by default. Is that possible?
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It only takes a minute to sign up.
Sign up to join this communityI see here:
How to specify a fill color in RGB format in a node in tikzpicture?
It is possible to change the color of a node locally. However, I would like to add a background color globally to all nodes by default. Is that possible?
Here is a possible way. Please note that it is generally not recommended to globally set such styles. I do not offer anything of the sort "fill only nodes with a border" since this is too much of a hack, and I do not see why this would be better than defining a style Draw/.style={draw=#1,fill=fillcolor}
and use this instead of draw. There is an if
named \iftikz@mode@draw
, but as you see it has @
inside, which indicates "do not mess with that unless you absolutely need to". So, unless you provide a very good argument why this is preferable to the above Draw
there is not much point IMHO to go this route. Anyway, here is how you could globally switch off and on fills.
\documentclass{article}
\usepackage{tikz}
\definecolor{fillcolor}{RGB}{255,51,76}
\begin{document}
\tikzset{nodes={fill=fillcolor}} % switch on global settings
\tikz{\node[draw]{Hello};}
\tikz{\node{World};}
\colorlet{fillcolor}{green}
\tikz{\node{Duck};}
\tikz{\node{Koala};}
\tikzset{every node/.style={}} %switch off global settings
\tikz{\node{Squirrel};}
\end{document}
\tikzset{nodes={fill=blue}}
?