2

I found this tree example 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
% https://www.packtpub.com/hardware-and-c ... x-cookbook
\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.

enter image description here How do fix the overlapping leaves, or how do set the length for the branches individually...

noob
  • 45
  • https://tex.stackexchange.com/questions/158940/distance-between-tree-levels-in-tikz-edges-and-node-centering might be able to solve ur problem. – Long Gong Aug 29 '17 at 18:17

1 Answers1

1

two version: with tikz tree and with forest:

\documentclass[tikz, margin=3mm]{standalone}
\usepackage{forest}

\begin{document}
    \begin{tikzpicture}[
every node/.style = {shape=rectangle, rounded corners, draw,
                     top color=white, bottom color=blue!20},
   level distance = 4em,
   level 1/.style = {sibling distance=24mm},
   level 2/.style = {sibling distance=16mm},
   level 3/.style = {sibling distance=8mm},
                        ]
\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}

   \begin{forest}
    for tree={% style of tree nodes
      draw, semithick, rounded corners,
        top color = red!10,
     bottom color = red!40,
               % style of tree (edges, distances, direction)
             grow = 270,
            s sep+ = 2mm,    % minimal (sibling) distance
            l sep+ = 4mm,    % level distance
               }
[Sentence
    [W1
        [M1
            [P1]
            [P2]
        ]
        [M2
            [P1]
            [P2]
        ]
    ]
    [W2
        [M1
            [P1]]
    ]
    [W3
        [M1]
        [M2]
    ]
];
    \end{forest}
\end{document}
    \end{document}

with tikz:

enter image description here

with forest:

enter image description here

advantages of forest is that it take over the care for distances between nodes.

Zarko
  • 296,517