LaTeX forum ⇒ Text FormattingFitting 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

Postby 215 » Tue Aug 29, 2017 7:26 pm

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:

  1. % A simple Tree
  2. % Author: Stefan Kottwitz
  3. \documentclass[border=10pt]{standalone}
  4. %%%<
  5. \usepackage{verbatim}
  6. %%%>
  7. \begin{comment}
  8. :Title: A simple Tree
  9. :Tags: Trees;Cookbook
  10. :Author: Stefan Kottwitz
  11. :Slug: tree
  12.  
  13. A simple tree with a style for all nodes.
  14. \end{comment}
  15.  
  16. \usepackage{tikz}
  17. \begin{document}
  18. \begin{tikzpicture}[sibling distance=15em,
  19. every node/.style = {shape=rectangle, rounded corners,
  20. draw, align=center,
  21. top color=white, bottom color=blue!20}]]
  22. \node {Sentence}
  23. child { node {W1}
  24. child { node {M1}
  25. child { node {P1}}
  26. child { node {P2}}}
  27. child { node {M2}
  28. child { node {P1}}
  29. child { node {P2}}}}
  30. child { node {W2}
  31. child { node {M1}
  32. child { node {P1} }}}
  33. child { node {W3}
  34. child { node {M1} }
  35. child { node {M2} }};
  36.  
  37. \end{tikzpicture}
  38. \end{document}


Creating this image.

tree.png
tree.png (19.92 KiB) Viewed 223 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

User avatar
Stefan Kottwitz
Site Admin
Posts: 8544
Joined: Mon Mar 10, 2008 9:44 pm
Location: Hamburg, Germany
Contact:

Postby Stefan Kottwitz » Wed Aug 30, 2017 1:29 am

Hi,

welcome to the forum!

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

  1. \documentclass[border=10pt]{standalone}
  2. \usepackage{tikz}
  3. \begin{document}
  4. \begin{tikzpicture}[%sibling distance=15em,
  5. level 1/.style={sibling distance=8em},
  6. level 2/.style={sibling distance=6em},
  7. level 3/.style={sibling distance=3em},
  8. every node/.style = {shape=rectangle, rounded corners,
  9. draw, align=center,
  10. top color=white, bottom color=blue!20}]]
  11. \node {Sentence}
  12. child { node {W1}
  13. child { node {M1}
  14. child { node {P1}}
  15. child { node {P2}}}
  16. child { node {M2}
  17. child { node {P1}}
  18. child { node {P2}}}}
  19. child { node {W2}
  20. child { node {M1}
  21. child { node {P1} }}}
  22. child { node {W3}
  23. child { node {M1} }
  24. child { node {M2} }};
  25. \end{tikzpicture}
  26. \end{document}


tree-adjusted.png
tree-adjusted.png (15.57 KiB) Viewed 222 times
Site admin


Return to “Text Formatting”

Who is online

Users browsing this forum: No registered users and 4 guests