# TikZ/PGF - switching off shading

Is there a way to switch off shading for one node, in a scope where the nodes are shaded? In other words, I want something like shading=none, but did not find it. Motivation:

\documentclass{article}
\usepackage{tikz}
\tikzset{default/.style={}}
\tikzstyle{st1}=[circle, shading=ball, ball color=red, inner sep=1.5pt]
\tikzstyle{st2}=[default, rectangle, inner xsep=0pt, inner ysep=2pt, draw]
\begin{document}
\begin{tikzpicture}[grow=right, level distance=10pt, every node/.style={st1}]
\path node{} child {node{} child {node{} child {node[st2]{}}}};
\end{tikzpicture}
\end{document}


This gives the following result: . The problem is that the shading is inherited in the last node, which I want without shading. I thought the default option in definition of st2 might help, but it does not have any effect.

The only way to achieve what I want is to add [every node/.style={default}] to the last child in the command; this resets/clears the style for all children. While writing this question, I realized that I can define \tikzstyle{st3}=[every node/.style={default, st2}] and use it on the last child. This makes it easy to use - but I would still like to know why I have to put the 'style reset' on the child, instead of on the node?

And one more thing: the reason I have inner ysep=0.0pt on the last node is that I actually want a single line, i.e. a box with zero width. Is there a way to achieve this in my setup, i.e. in a sequence of nodes?

Thanks.

-
Sorry, could you point me where did you find the default option? I looked for it in the manual without success. –  Claudio Fiandrino Dec 6 '12 at 8:41
@ClaudioFiandrino It is used on four different places in the manual, just search for =default. Somehow, I noticed it and I tried it for styles .. and it works, in a way :-) –  Michal Kaut Dec 6 '12 at 9:29
@MichalKaut: The default style is not defined on my system (TiKZ/PGF v2.1) and throws an error. I also can't find it in the manual (only as a value that's passed to other keys, but not as an independent style). Are you using a different version of TikZ/PGF? –  Jake Dec 6 '12 at 9:32
Oh you're right. Unfortunately when I built a mwe with that key I got: ! Package pgfkeys Error: I do not know the key '/tikz/default' and I am going to ignore it. Indeed, for what I understood, default is used to reset values to the original configuration in baseline, trim left, trim right –  Claudio Fiandrino Dec 6 '12 at 9:37
@MichaelKaut: Updating the post is probably a good idea. In general, it's always preferred to post complete minimal documents (so starting from \documentclass and containing only those things necessary to demonstrate the problem). That avoids ambiguity and makes it easier for others to come up with a solution. By the way, your definition of default does not have any effect on anything. \node [default] {...} is equivalent to \node [] {...}. –  Jake Dec 6 '12 at 9:51

At the moment, the shade key is only a one way switch: It only switches shadings on, but it can't switch them off. It's easy to redefine, however:

\makeatletter
\def\tikz@falsetext{false}
\tikzset{
\edef\tikz@temp{#1}%
\ifx\tikz@temp\tikz@falsetext%
\else%
\fi
}
}
\makeatother


Now you can say shade=false to deactivate the shading:

\documentclass[a4paper]{article}
\usepackage{tikz}

\makeatletter
\def\tikz@falsetext{false}
\tikzset{
\edef\tikz@temp{#1}%
\ifx\tikz@temp\tikz@falsetext%
\else%
\fi
}
}
\makeatother

\begin{document}
\tikzset{
st1/.style={circle, shading=ball, ball color=red, inner sep=1.5pt},
st2/.style={rectangle, shade=false, inner xsep=1.5pt, inner ysep=0.0pt, draw}
}

\begin{tikzpicture}[grow=right, level distance=10pt, every node/.style={st1}]
\path node{} child {
node{} child {
node{} child {
node[st2]{}
}
}
};
\end{tikzpicture}
\end{document}

-
I didn't believe this so I looked in the code .. absolutely right! I guess no-one thought that one might want to set shading on by default and switch it off on occasion. –  Loop Space Dec 6 '12 at 9:29
Much more simpler than mine: +1 :) –  Claudio Fiandrino Dec 6 '12 at 9:38
@AndrewStacey Thanks, this solves the problem. By the way, does it mean that there is no simple way to reset the style of a single node, using its properties ([]), in the same way I can reset style for its children using child[every node/.style={}]? –  Michal Kaut Dec 6 '12 at 10:14

Here is a ... ehm ... wonderful, fantastic, new shading called none. It basically fills the node and does nothing else. One can use it in the same way of a ball shading, so by means of shading=none; to specify the color I was in doubt if let this operation to fill or not, then I preferred keeping the same behaviour of the other shadings, so there's a none shade color key defined.

An example:

\documentclass[a4paper]{article}
\usepackage{tikz}

\makeatletter

color(0bp)=(tikz@none@color);
color(25bp)=(tikz@none@color);
color(50bp)=(tikz@none@color);
color(75bp)=(tikz@none@color);
color(100bp)=(tikz@none@color)}

\pgfutil@colorlet{tikz@none@color}{white}
\makeatother

\begin{document}
\tikzset{st1/.style={circle, shading=ball, ball color=red, inner sep=1.5pt}}
% one could also avoid saying shading=none and just specifying the color, as for the ball shading
\tikzset{st4/.style={circle,  inner sep=1.5pt, none shade color=blue!50}}
\begin{tikzpicture}[grow=right, level distance=10pt, every node/.style={st1}]
\path node{} child {node[st2]{} child {node{} child {node[st2]{} child{node[st3]{} child{node[st4]{}}}}}};
\end{tikzpicture}
\end{document}


The result:

BTW: in the original code I replaced \tikzstyle with \tikzset as per Should \tikzset or \tikzstyle be used to define TikZ styles?.

-
That is a lot of code to switch something off, but it works nicely. Thanks a lot. (And thanks to the pointer to the \tikzstyle vs. \tikzset issue, I was not aware of this.) –  Michal Kaut Dec 6 '12 at 9:52
This actually is not a code to switch off the shading, but rather to override a previous shading mode with something that is still defined as a shading without behaving as a shading. Yes: my mind is complicated. :) –  Claudio Fiandrino Dec 6 '12 at 9:56