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 been struggling a bit with TikZ and how to build trees. What I need now is some advice on how to improve the node placement. Right now I have these 2 trees:

\documentclass[a4paper,10pt]{article}
\usepackage{tikz}
\usetikzlibrary{positioning,shadows,arrows,trees,shapes,fit}
\begin{document}
\begin{tikzpicture}
[font=\small, edge from parent fork down, 
every node/.style={top color=white, bottom color=blue!25, 
rectangle,rounded corners, minimum size=6mm, draw=blue!75,
very thick, drop shadow, align=center},
edge from parent/.style={draw=blue!50,thick},
level 1/.style={sibling distance=6cm},
level 2/.style={sibling distance=2.5cm}, 
level 3/.style={sibling distance=2.5cm}, 
level distance=2cm,
]

\node {Paletizar} % root
    child { node {Iniciar} 
        child { node {Detectar Pacote}}
        child { node {Movimentar}}
        }
    child { node {Empacotar}
        child { [sibling distance=15mm] node {Posicionar}
            child { node {Pegar/Largar}}
            child { node {Organizar}}
            child { node {Movimentar}}
            }
        child { node {Agrupar}}
        child { node {Padronizar}}
        }
    child { node {Finalizar} 
        child { node {Detectar estado\\da palete}}
        child { node {Transmitir}}
};
\end{tikzpicture}


\vspace{2cm}

\begin{tikzpicture}
[font=\small, edge from parent fork down, 
    every node/.style={top color=white, bottom color=blue!25, 
    rectangle,rounded corners, minimum size=6mm, draw=blue!75,
    very thick, drop shadow, align=center},
    edge from parent/.style={draw=blue!50,thick},
    level 1/.style={sibling distance=6cm},
    level 2/.style={sibling distance=3cm}, 
    level 3/.style={sibling distance=2cm}, 
    level distance=2cm,
    ]

    \node {Paletizador} % root
        child { node {Inicialização\\de sistema} 
            child { node {Sensor X}}
            child { node {Acção Y}}
            }
        child { node {Sacos}
            child { node {Linha/Coluna}
                child { node {Garra}}
            child { node {Rodar Garra}}
            child { node {Acção Y2}}
            }
        child { node {Euro Pallet}}
        child { node {Disposição $xyz$}
            child { node {$x=?$}}
            child { node {$y=?$}}
            child { node {$z=?$}}
            }
        }
    child { node {Sistema de despacho} 
        child { node {Sensor de peso\\/contador}}
        child { node {Tapete rolante\\de saída}}
};
\end{tikzpicture}

\end{document}

So basically what I want is a way to edit the code I have so that everything is perceptible which basically means that I need specific sibling distances to each child. I have tried to add a sibling distance in the child nodes but maybe it was in the wrong place or something else because it didn't change anything. I also tried to use below and all its derivations but the results were even worse because of the size of the boxes.

share|improve this question
    
Welcome to TeX.sx! It's not necessary to sign your questions (as there is already a box with your username below it) or to begin them with a greeting. –  Torbjørn T. Nov 20 '11 at 20:34
add comment

2 Answers

up vote 10 down vote accepted

Using tikz-qtree helps a bit with automatic spacing of siblings. It also provides a simpler input method. Here's your second tree done in that way:

\documentclass[landscape]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}

\usepackage[margin=1in]{geometry}
\usepackage{tikz-qtree}
\usetikzlibrary{shadows,trees}
\begin{document}
\tikzset{font=\small,
edge from parent fork down,
level distance=1.75cm,
every node/.style=
    {top color=white,
    bottom color=blue!25,
    rectangle,rounded corners,
    minimum height=8mm,
    draw=blue!75,
    very thick,
    drop shadow,
    align=center,
    text depth = 0pt
    },
edge from parent/.style=
    {draw=blue!50,
    thick
    }}

\centering
\begin{tikzpicture}
\Tree [.Paletizador
        [.{Inicialização\\de sistema}
            [.{Sensor X} ]
            [.{Acção Y} ] ] 
        [.Sacos
            [.{Linha/Coluna} 
                [.{Garra} ]
                [.{Rodar Garra} ]
                [.{Acção Y2} ] ]
            [.{Euro Pallet} ]
            [.{Disposição $xyz$}
                [.{$x=?$} ]
                [.{$y=?$} ]
                [.{$z=?$} ] ] ] 
        [.{Sistema de despacho}
            [.{Sensor de peso\\/contador} ]
            [.{Tapete rolante\\de saída} ] ]
]
\end{tikzpicture}
\end{document}

output of code

share|improve this answer
    
tkiz-qtree helps a lot (I was actually learning how to use it now). However it does create a couple of blank spaces. Is there a way to compact it? Also I seem to loose some horizontal alignment, is there a way to fix that? Other than that it's perfect –  Duarte Silva Nov 20 '11 at 22:48
    
Do you mean the space around the "Linha/Coluna" node? That's determined by the width of its daughter nodes; I don't think there's an easy way to adjust that. As for the alignment of the "y=?" node, I have no idea why that is not aligned properly. –  Alan Munn Nov 20 '11 at 23:04
    
Ok, I'll leave it at that. Maybe when I have more time I'll try again. Thanks to everyone –  Duarte Silva Nov 20 '11 at 23:10
    
Thanks to @Jake, there's a solution to the horizontal alignment problem: I've added text depth=0pt to the node style parameters. –  Alan Munn Nov 21 '11 at 0:27
add comment

I am not completely sure that this is actually what you want. You can easily change your code a bit to get everything to fit though. Adding the fullpage package to ensure it fits on the page properly and slightly adjusting the sibling distances for the different levels is enough.

\documentclass[a4paper,10pt]{article}
\usepackage{tikz}
\usepackage{fullpage}
\usetikzlibrary{positioning,shadows,arrows,trees,shapes,fit}
\begin{document}
\begin{tikzpicture}
[font=\small, edge from parent fork down, 
every node/.style={top color=white, bottom color=blue!25, 
rectangle,rounded corners, minimum size=6mm, draw=blue!75,
very thick, drop shadow, align=center},
edge from parent/.style={draw=blue!50,thick},
level 1/.style={sibling distance=6cm},
level 2/.style={sibling distance=2.5cm}, 
level 3/.style={sibling distance=2.5cm}, 
level distance=2cm,
]
\node {Paletizar} % root
    child { node {Iniciar} 
        child { node {Detectar Pacote}}
        child { node {Movimentar}}
        }
    child { node {Empacotar}
        child { [sibling distance=15mm] node {Posicionar}
            child { node {Pegar/Largar}}
            child { node {Organizar}}
            child { node {Movimentar}}
            }
        child { node {Agrupar}}
        child { node {Padronizar}}
        }
    child { node {Finalizar} 
        child { node {Detectar estado\\da palete}}
        child { node {Transmitir}}
};
\end{tikzpicture}

\vspace{2cm}
\begin{tikzpicture}
[font=\small, edge from parent fork down, 
    every node/.style={top color=white, bottom color=blue!25, 
    rectangle,rounded corners, minimum size=6mm, draw=blue!75,
    very thick, drop shadow, align=center},
    edge from parent/.style={draw=blue!50,thick},
    level 1/.style={sibling distance=6cm},
    level 2/.style={sibling distance=2.5cm}, 
    level 3/.style={sibling distance=1.75cm}, 
    level distance=2cm,
    ]
    \node {Paletizador} % root
        child { node {Inicialização\\de sistema} 
            child { node {Sensor X}}
            child { node {Acção Y}}
            }
        child { node {Sacos}
            child { node {Linha/Coluna}
                child { node {Garra}}
            child { node {Rodar Garra}}
            child { node {Acção Y2}}
            }
        child { node {Euro Pallet}}
        child { node {Disposição $xyz$}
            child { node {$x=?$}}
            child { node {$y=?$}}
            child { node {$z=?$}}
            }
        }
    child { node {Sistema de despacho} 
        child { node {Sensor de peso\\/contador}}
        child { node {Tapete rolante\\de saída}}
};
\end{tikzpicture}
\end{document}

TikZ Tree diagram

You might want to look into some other package, like qtree to draw your trees, if the nodes don't need to look as fancy and you want some automatic placement. If you do want the fancyness of TikZ, there is also tikz-qtree.

share|improve this answer
1  
Since qtree is designed solely for linguistic trees, it has few options for changing the branch shape, so for these kinds of trees, tikz-qtree is a better choice. –  Alan Munn Nov 20 '11 at 21:16
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.