# Overriding node draw style inherited from every node style messes up positioning

I have been trying to draw a tree with TikZ. All nodes should be circles, so I use the every node style. There are some additional labels on some nodes, which have to be exceptions. I have tried this:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning}
\begin{document}
\begin{tikzpicture}[every node/.style={draw,circle}]
\node {A}
child { node (b) {B} }
child { node {C} };
\node[draw=none,below=1mm of b] {hint};
\end{tikzpicture}
\end{document}


But the hint is too far away from B:

When I remove the every node style, the positioning is correct:

How can I fix this?

-
This problem cost me quite some time when it occurred, so I thought I'd put it up in the spirit of Encyclopedia Stack Exchange. Maybe there are better solutions than mine. –  Raphael Mar 5 '13 at 14:07

Aside from the fact that I should probably not have used every node for this purpose, the underlying problem is simple, but somewhat hidden in the documentation (according to my limited efforts).

draw=none turns off the drawing of the shape but does not do away with the shape itself! Therefore, the hint node keeps the circle shape from every node which causes the positioning:

There does not seem to be a null-shape. The standard shape is rectangle, so resetting to this

\node[draw=none,rectangle,below=1mm of b] {some hint for B};


provides the desired result:

-
another solution, is to put the [every node...] on the first node creating the diagram: \node[every node/.style={draw,circle}] {A} ... or one could use scopes, etc. There are many possibilities. :) Maybe you could add them? –  zeroth Mar 5 '13 at 14:38
By the way, your remark about a null-shape gave me this idea, which can be useful sometimes: \tikzset{no shape/.style = {rectangle, inner sep=0pt, draw=none, fill=none }} –  JLDiaz Mar 5 '13 at 14:41
@zeroth That's probably a better way to perform the original task, but does not relate to the "positioning problem" which I wanted to address here. –  Raphael Mar 5 '13 at 14:47
@JLDiaz You will also need to re-set minimum size and what not … –  Qrrbrbirlbel Mar 5 '13 at 14:51

Raphael’s own answer is of course correct: The hint node inherits the every node styles.

If you only want to change the tree’s nodes, you can set the every node style locally to the tree if you use

\path[options] node {parent node} child …


While the positioning is great, a simple hint like that can be placed with the help of the label options. There is no need to name the node (b) anymore and one can easily change the text without researching which hint belongs to which node.

Note that I have used .append style handler, especially for the every label style. When a label (which is just a node, too) is placed it inherits also the every node style, but the every label style overwrites any possible settings.

This can be seen if you use the every label/.style instead of .append style. Suddenly the shape’s border is visible because the .style handler overwrites an already existing draw=none in the every label style.

## Code

\documentclass[tikz]{standalone}
\usetikzlibrary{positioning}
\begin{document}
\begin{tikzpicture}
\path[every node/.append style={draw,circle}] node {A}
child { node (b) {B} }
child { node {C} };
\node[draw=none,below=1mm of b] {some hint for B};
\end{tikzpicture}

\begin{tikzpicture}[
every label/.append style={shape=rectangle},% these three options could have
label distance=1mm,                         % been assigned to a \path
every node/.append style={draw,circle},     % like in the example above.
]
\node {A}
child { node[label=below:some hint for B] {B} }
child { node {C} };
\end{tikzpicture}
\end{document}


## Output

-
This is probably a better way to code the thing, circumventing the problem I have addressed. –  Raphael Mar 5 '13 at 14:49