2

I am fairly new to latex and I am trying to do a tree graphics with the forest package on sharelatex. My problem is that I have a really large tree with a lot of child entries under the same parent. How can I make it so that it can fit better on a page. Would it help if the tree expanded horizontally instead of vertically? Can I make it so that entries to the same levels in the tree are on different heights? Here is the base code I am using for my tree so far.

\documentclass[tikz,border=10pt]{standalone}
\usepackage[linguistics]{forest}

\begin{document}
\begin{forest}

  [Parent
    [subparent 1
       [1]
       [2]
       [3]
%...
       [10]
    ]
    [subparent 2
       [1]
       [2]
       [3]
%...
       [8]
    ]
  ]
\end{forest}
\end{document}
3
  • 1
    for tree={ grow=east } ? (Note also that the empty line after \begin{forest} causes an error.)
    – user121799
    Jun 18 '18 at 10:15
  • Thank you @marmot that command helped me plenty. Now I have a problem where the lines cross over the text for some items. Is there any way to put the lines behind. How it looks. ( I also added a frame for each item with for tree={draw}.)
    – Joey
    Jun 18 '18 at 11:20
  • It is really hard to be helpful without code to produce the problematic output. (In this case, we don't even have the problematic output necessary to recreate the code, so are even more in the dark.)
    – cfr
    Jun 18 '18 at 22:44
2

That's not a complete answer but just to tell you how to put the edges always behind the nodes. As this issue does not arise in the example you post, I just took an example from the forest manual.

\documentclass[tikz,border=10pt]{standalone}
\usetikzlibrary{backgrounds}
\usepackage[linguistics]{forest}

\begin{document}
\begin{forest} % example from section 6.2 of the forest manual
for tree={
fill=white, fill opacity=0.7,%<-added
calign=first,
edge path={ \noexpand\begin{scope}[on background layer]
\noexpand\path [draw,\forestoption{edge}] (!u.parent anchor) -- (.child anchor)\forestoption{edge label}; 
\noexpand\end{scope}}, %<- added
}
[R[AAAAAAAAAA\\AAAAAAAAAA\\AAAAAAAAAA,align=center,base=bottom][B]]
\end{forest}
\end{document}

enter image description here

If you remove the opacity statement, the line will be completely hidden.

Ah, and as for your question, you may want to add grow=east (just in case I remove the comment above).

5
  • to my taste i would consider forked edge(s) :-).
    – Zarko
    Jun 18 '18 at 15:05
  • @Zarko Did you read the OP's question and comment below it? It seems that his tree is too crowded and he was asking for a way to draw the edge behind the node.
    – user121799
    Jun 18 '18 at 15:07
  • i must confess, that i didn't read comment :-(, however, forked edge is nicer solution. it can put nodes in two levels as i show in one of my answers (unfortunately i cant find it temporary and my pause between my work is over. i will try again at next pause)
    – Zarko
    Jun 18 '18 at 15:26
  • @Zarko I definitely agree that forked edges are nice in most situations - unless the tree is so dense that it becomes impossible to wiggle your way through the forest, then you need to go hide ;-)
    – user121799
    Jun 18 '18 at 15:35
  • i'm sorry, but i'm not able to find question/answer which show how to arrange nodes of one level in two lines. i suspect, that op is removed from list (few days ago i lost some reputation on this regards). unfortunately i didn't copy this interesting solution ... for replication of it the op should provide more complete example of the his tree. and +1 for your nice solution :-)
    – Zarko
    Jun 18 '18 at 19:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.