Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I have this TikZ code:

\documentclass{minimal}
\usepackage{tikz}
\usetikzlibrary{positioning}
\begin{document}

\begin{tikzpicture} [
    level 1/.style={sibling distance = 2cm, level distance = 1cm},
    level 2/.style={sibling distance = 1cm},
    level 3/.style={sibling distance = 1cm},
    every node/.style={circle, draw=black, minimum size = 0.5cm},
    edge from parent/.style={red,thick,draw}
  ]

  \node{} 
  child { node {}
    child { node {} }
    child { node {}
      child { node {} }
      child { node {} }
    }
  }
  child { node {}
    child { node {} }
    child { node {} }
  }
  child { node {} }
  ;

\end{tikzpicture}
\end{document}

And it produces this picture:

buggy render

Why are the bottom nodes thick?

share|improve this question
    
PS: Why level distance set for level 1 affects all levels? –  Łukasz Lew Jan 18 '11 at 18:33
    
Always best to have compilable code. –  Hendrik Vogt Jan 18 '11 at 18:37
    
Thanks for edit. –  Łukasz Lew Jan 18 '11 at 18:41
add comment

2 Answers

up vote 7 down vote accepted

Styles are inherited to the child nodes. The manual addresses this in the note at the end of section 18.6. This happens in other places with Tikz as well.

The solution in this case would be to override it by specifying the style for "every node", i.e.

every node/.style={circle, draw=black, thin, minimum size = 0.5cm}

Note that "thin" is actually the normal line width.

Edit: Since there was a reply while I was looking things up, I thought I'd bring in some more information by quoting the relevant section in the manual;

Besides inserting the edge from parent path, the edge from parent operation has another effect: The options are inserted directly before the edge from parent path and the following style is also installed prior to inserting the path:

Note: The options inserted before the edge from parent path is added apply to the whole child path. Thus, it is not possible to, say, draw a circle in red as part of the child path and then have an edge to parent in blue. However, as always, the child node is a node and can be drawn in a totally different way.

For the follow up question regarding modifying specific paths. I would interpret the manual as you will have to do apply styles to nodes manually.

\documentclass{minimal}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture} [
    level 1/.style={sibling distance = 2cm, level distance = 1cm},
    level 2/.style={sibling distance = 1cm},
    level 3/.style={sibling distance = 1cm},
    every node/.style={circle, draw=black, minimum size = 0.5cm}
   ]
  \begin{scope}[xshift=6cm, edge from parent/.style={red,thin,draw}]
    \node{}
    child { node {}
      child { node {} }
      child { node {} edge from parent[thick]
        child { node[thin] {} } % Overriding the inherited thick property.
        child { node[thin] {} } % Overriding the inherited thick property.
       }
    }
    child { node {}
      child { node {} }
      child { node {} }
    }
    child { node {} }
    ;
  \end{scope}
\end{tikzpicture}
\end{document}
share|improve this answer
    
Thanks for your help! –  Łukasz Lew Jan 18 '11 at 19:48
add comment

The problem is caused by the thick parameter in the edge from parent.style command. If you add thin to the specification of your every node style, the problem goes away.

\begin{tikzpicture} [
    level 1/.style={sibling distance = 2cm, level distance = 1cm},
    level 2/.style={sibling distance = 1cm},
    level 3/.style={sibling distance = 1cm},
    every node/.style={circle, draw=black,thin, minimum size = 0.5cm}
  ]
...
share|improve this answer
    
Actually I wanted to thicken few edges in the tree, but if I use "edge from the parent[thick]" in the middle of the tree, the results are unpredictable. I don't know how to work around it. –  Łukasz Lew Jan 18 '11 at 18:53
    
@Lukasz What do you mean by "unpredictable". Can you edit your question then to show that problem? If I remove the edge from parent specification from the scope command, and put [edge from parent/.style={red,thick,draw}] next to any individual child in your example, it works as you would expect. (But see Mikael's answer for details on how if you specify it higher in the tree it propagates down.) –  Alan Munn Jan 18 '11 at 19:15
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.