## LaTeX forum ⇒ Text Formatting ⇒ Fitting the length of each branch for this tree

Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
215
Posts: 1
Joined: Tue Aug 29, 2017 7:01 pm

### Fitting the length of each branch for this tree

I found this tree example from the LaTeX Cookbook in

http://www.texample.net/tikz/examples/tree/

Which i've used to build my own tree, but i have some problems with the length of the branch being the samme for all of them, thereby making some of the leaves overlap..

as seen here:

% A simple Tree% Author: Stefan Kottwitz\documentclass[border=10pt]{standalone} %%%<\usepackage{verbatim}%%%>\begin{comment}:Title: A simple Tree:Tags: Trees;Cookbook:Author: Stefan Kottwitz:Slug: tree A simple tree with a style for all nodes.\end{comment} \usepackage{tikz}\begin{document}\begin{tikzpicture}[sibling distance=15em,  every node/.style = {shape=rectangle, rounded corners,    draw, align=center,    top color=white, bottom color=blue!20}]]  \node {Sentence}    child { node {W1}         child { node {M1}             child { node {P1}}            child { node {P2}}}        child { node {M2}             child { node {P1}}            child { node {P2}}}}    child { node {W2}         child { node {M1}            child { node {P1} }}}    child { node {W3}         child { node {M1} }        child { node {M2} }};     \end{tikzpicture}\end{document}

Creating this image.

tree.png (19.92 KiB) Viewed 329 times

How do fix the overlapping leaves, or how do set the length for the branches individually...
Last edited by Stefan Kottwitz on Wed Aug 30, 2017 1:20 am, edited 1 time in total.
Reason: code syntax highlighting, Links, external image attached

Stefan Kottwitz
Posts: 8705
Joined: Mon Mar 10, 2008 9:44 pm
Location: Hamburg, Germany
Contact:
Hi,

welcome to the forum!

You can adjust the sibling distance for each level individually, such as:

\documentclass[border=10pt]{standalone} \usepackage{tikz}\begin{document}\begin{tikzpicture}[%sibling distance=15em,    level 1/.style={sibling distance=8em},    level 2/.style={sibling distance=6em},    level 3/.style={sibling distance=3em},  every node/.style = {shape=rectangle, rounded corners,    draw, align=center,    top color=white, bottom color=blue!20}]]  \node {Sentence}    child { node {W1}         child { node {M1}             child { node {P1}}            child { node {P2}}}        child { node {M2}             child { node {P1}}            child { node {P2}}}}    child { node {W2}         child { node {M1}            child { node {P1} }}}    child { node {W3}         child { node {M1} }        child { node {M2} }};    \end{tikzpicture}\end{document}

tree-adjusted.png (15.57 KiB) Viewed 328 times