LaTeX forum ⇒ Graphics, Figures & Tablestikz-qtree | Several Lines per Node Topic is solved

Information and discussion about graphics, figures & tables in LaTeX documents.
Laurentius
Posts: 132
Joined: Wed Feb 11, 2009 11:38 pm

tikz-qtree | Several Lines per Node

Postby Laurentius » Wed Apr 18, 2012 3:44 pm

  1. \documentclass{article}
  2. \usepackage{tikz}
  3. \usepackage{tikz-qtree}
  4. \begin{document}
  5. \noindent\makebox[\textwidth]{
  6. \begin{tikzpicture}
  7. \tikzset{edge from parent/.style=
  8. {draw,
  9. edge from parent path={(\tikzparentnode.south)
  10. -- +(0,-8pt)
  11. -| (\tikzchildnode)}}}
  12. \tikzset{every tree node/.style={align=center,anchor=north}}
  13. \tikzset{level distance=40pt}%,sibling distance=0pt}
  14. \baselineskip=0pt
  15. \Tree [ .{a} [ .{x} {b,\\c} [ .{d\\f\\g\\h}
  16. [ .{d} {d} {f} ] [ .{g} {d}
  17. \node(pr){gs}; ] ] ] [ .{dsfg} \node(lgst){asdf};
  18. {sdg} ] ]
  19. \draw[<-] (pr)..controls +(east:1) and +(south:1) .. (lgst);
  20. \end{tikzpicture}}
  21. \end{document}



Here, several lines per node is allowed by
\tikzset{style={align=center,anchor=north}}
but this messes up the tree (the length of the branches).
Can this be remedied?

Link:
BBcode:
HTML:
Hide post links
Show post links

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

Postby Stefan Kottwitz » Wed Apr 18, 2012 5:54 pm

You could apply the style locally, where needed.

I would define a multi-line style, so it's easier to adjust and better readable in the tree code:

  1. \tikzset{multiline/.style={align=center,anchor=north}}


In the tree, you can write the node with this style, where needed, such as

  1. ... [ .\node [multiline] {d\\f\\g\\h}; [ ...

Furthermore, you probably need to adjust the level distance, because multi-line nodes are higher.

Stefan
Site admin

Link:
BBcode:
HTML:
Hide post links
Show post links

Laurentius
Posts: 132
Joined: Wed Feb 11, 2009 11:38 pm

Postby Laurentius » Wed Apr 18, 2012 7:52 pm

It seems impossible to change the level distance for individual nodes inside the tree.

Link:
BBcode:
HTML:
Hide post links
Show post links

Laurentius
Posts: 132
Joined: Wed Feb 11, 2009 11:38 pm

Postby Laurentius » Wed Apr 18, 2012 8:00 pm

It seems impossible to change the level distance for individual nodes inside the tree.

Here is a better example:

  1. \documentclass{article}
  2. \usepackage{tikz}
  3. \usepackage{tikz-qtree}
  4. \begin{document}
  5. \noindent\makebox[\textwidth]{
  6. \begin{tikzpicture}
  7. \tikzset{edge from parent/.style=
  8. {draw,
  9. edge from parent path={(\tikzparentnode.south)
  10. -- +(0,-8pt)
  11. -| (\tikzchildnode)
  12. }
  13. }
  14. }
  15. \tikzset{align=center,level distance=45}
  16. \Tree
  17. [ .{psyche}
  18. [ .{alogon}
  19. {threptikon,\\phytikon}
  20. [ .{(echon pos)\\orektikon}
  21. [ .{para}
  22. {epithymetikon} {thymetikon}
  23. ]
  24. [ .{echon pos,\\akoustikon}
  25. {bouleutikon} \node(pr){proairektikon,\\hegemonikon};
  26. ] ] ]
  27. [ .{echon}
  28. \node(lgst){logistikon,\\bouleutikon}; {epistemonikon}
  29. ] ]
  30. \draw[<-] (pr)..controls +(south east:3) and +(south:1) .. (lgst)
  31. node[midway,right]{bouleuton,\\proaireton\\(pros ta tele)};
  32. \end{tikzpicture}}
  33. \end{document}

Link:
BBcode:
HTML:
Hide post links
Show post links

Laurentius
Posts: 132
Joined: Wed Feb 11, 2009 11:38 pm

Postby Laurentius » Thu Apr 19, 2012 6:51 pm

Perhaps the problem could be solved if the new lines could be added below the first instead of above it, but I don't know if this is possible -- ?

Link:
BBcode:
HTML:
Hide post links
Show post links

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

Postby Stefan Kottwitz » Wed Apr 25, 2012 11:01 pm

David Chiang and Andrew Stacey have improved the tikz-qtree package. Now it's possible to define level based styles, such as level distance and sibling distance. You can try if you add to your code:

  1. \tikzset{level 1/.style={level distance=30pt}}
  2. \tikzset{level 2/.style={level distance=40pt, sibling distance=20pt}}
  3. \tikzset{level 3+/.style={level distance=40pt, sibling distance=10pt}}


Here you can see the result with different distances:

tree.png
TikZ qtree
tree.png (13.75 KiB) Viewed 4002 times


You just need to update your package. The new features are documented in the up-to-date tikz-qtree manual, in 3.3 Node placement styles.

Stefan
Site admin

Link:
BBcode: Topic is solved[/url]" title="Click to select post's link in BBcode format" onclick="this.focus();this.select();" />
HTML: Topic is solved</a>" title="Click to select post's link in HTML format" onclick="this.focus();this.select();" />
Hide post links
Show post links

Laurentius
Posts: 132
Joined: Wed Feb 11, 2009 11:38 pm

Postby Laurentius » Sat Apr 28, 2012 2:22 pm

Wunderbar! Besten Dank!

L.

Link:
BBcode:
HTML:
Hide post links
Show post links


Return to “Graphics, Figures & Tables”

Who is online

Users browsing this forum: Google [Bot] and 6 guests