1

In the middle of drawing blooming tree, which is declared in generic way, something is going wrong. Please, help me to separate middle nodes and put boxes with borders on every node.

\begin{tikzpicture}[text width=5cm, align=flush center,node distance=70mm, level 1/.style={sibling distance =30 mm}, level 2/.style={sibling distance =30 mm}, level 3/.style={sibling distance =30 mm}]
    \node{Static}
        child { node[color=red] {Node1}}
        child { 
            node{Static}
            child[color=brown] { 
            node {Node2}
            node[color=green]{dynamic}
            child[color=brown] { node {Node3}}
            child[color=gray] { node {Rest}} 
            }
        }
            ;
\end{tikzpicture}

Tree

  • And how should be the desired result? What do you want dynamic and Node 2 positions to be? I provided an answer below but it wasn't clear from your description how "Node2" and "Dynamic" shouls appear in the tree. If you desire another distribution, please let me know. – Gonzalo Medina Jun 29 '15 at 23:14
  • Thanks, you showed pretty good distribution, but I don't mind another one. I wish if they weren't placed in one place as sibling distance restricts it. – Constantin Novikov Jun 29 '15 at 23:30
  • I was wrong non-placing dynamic in child{} section. – Constantin Novikov Jun 29 '15 at 23:44
2

I'd like to suggest you the powerful forest package instead: it's built on top of TikZ and offers a cleaner, shorter syntax (amongst many other useful festures).

Here's the code with two versions: the first one using yout TikZ tree approach and the second one using forest:

\documentclass{article}
\usepackage{forest}
\usetikzlibrary{trees}

\begin{document}

\begin{tikzpicture}[
  every node/.style={draw,align=center}, 
  node distance=70mm, 
  level 1/.style={sibling distance =30 mm}, 
  level 2/.style={sibling distance =30 mm}, 
  level 3/.style={sibling distance =30 mm}
]
\node{Static}
        child { node[color=red] {Node1}}
        child { 
            node{Static}
            child[color=brown] { node {Node2}}
            child {
              node[color=green]{dynamic}
                child[color=brown] { node {Node3}}
                child[color=gray] { node {Rest}} 
            }
        }
            ;
\end{tikzpicture}\par\bigskip

\begin{forest}
for tree={
  draw,
  s sep=20mm
}
[Static
  [Node1,red
  ]
  [Static
    [Node2,brown]
    [Dynamic,green
        [Node3,brown]
        [Rest,gray]
    ]
  ]
]
\end{forest}

\end{document}

The result:

enter image description here

  • Still experiencing problems with Node2+Dynamic nodes placed in one place. Trying to get forest package to ease work with trees. – Constantin Novikov Jun 29 '15 at 23:28
  • @ConstantinNovikov As the image in my answer shows, using the code I posted they appear in different positions. In any case, yes, I recommend you to switch to forest. As I said, it has a cleaner, shorter syntax and many, many other interesting features for trees. – Gonzalo Medina Jun 29 '15 at 23:32
  • @ConstantinNovikov If you have a standard TeX installation, you should already have forest or (for MikTeX) it should be easy to install using the package manager or on-the-fly installation. Getting it shouldn't be hard or, even, something you need to do at all in most cases. – cfr Jun 29 '15 at 23:35
  • Yes, forest package works well, thanks. But your first variant of the tree compiles as I showed in opening picture, two nodes in one place and I consider it as misbehaviour of MiKTeX. After reeboot all your answers become to work as you showed. – Constantin Novikov Jun 29 '15 at 23:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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