3

MWE:

\documentclass{article}
\usepackage{tikz}
\usepackage[edges]{forest}

\newcommand{\nodecircle}{circle,fill,outer sep=0,inner sep=1pt}

\begin{document}

    \begin{forest}
        [,\nodecircle, alias = I, s sep=0.4cm,l sep=2cm,
        [Rain]
        [Shine]
        ] 
        \node[above] at (I){Nature}; 
    \end{forest}

\end{document}

This produces a forest with two nodes, growing downwards.

I know that to change the direction in which it grows, I have to use the grow = option command.

However, how do I make both child nodes grow in separate directions?

Specifically, I want the first child node to grow east, and the second to grow west.

However, how do I grow in two different directions from the same parent node? Specifically, I want the Rain node to be horizontally to the right (i.e east) and the Shine node to be west.

This question provides an answer which even the person who answered deemed not elegant. I was wondering if there is a newer way to do it.

7
  • There is an example on p. 42 of the forest manual.
    – user121799
    Nov 9, 2018 at 21:53
  • I'm not sure I get it. Which function am I looking for? Relative nodes?
    – Thev
    Nov 9, 2018 at 22:02
  • 1
    I was referring to "make nodes grow in separate directions".
    – user121799
    Nov 9, 2018 at 23:08
  • 1
    ... because you are looking at an older version of the manual.... in the link the example is on p. 30 ...
    – user121799
    Nov 9, 2018 at 23:24
  • 1
    @marmot I deeply apologise. I had unintentionally asked a different question than the one I meant to. I have edited the question, with the stupid phrasing struck out.
    – Thev
    Nov 9, 2018 at 23:37

1 Answer 1

2

This code works (based off Method 1 here):

\documentclass{article}
\usepackage{tikz}
\usepackage[edges]{forest}

\newcommand{\nodecircle}{circle,fill,outer sep=0,inner sep=1pt}

\begin{document}

\begin{forest}
    [,\nodecircle, alias = I, l sep=2cm, grow = east
    [,\nodecircle, before computing xy={l=3cm,s=0cm}, alias = rain]
    [,\nodecircle, before computing xy={l=-3cm,s=0cm}, alias = shine]
    ] 
    \node[above] at (I){Nature}; 
    \node[above] at (rain){Rain}; 
    \node[above] at (shine){Shine}; 
\end{forest}

\end{document}

More elegant solutions are very welcome.

3
  • If you are going to do this, you might as well either not use forest or just set them using label, because you're not using Forest to place them at all.
    – cfr
    Nov 11, 2018 at 0:37
  • I was basing this off Saso's answer at the question I linked to. I found this to be a workable solution, since I could grow the rest of my tree easily from here (I have found forest the easiest package to work with generally). If you have a more elegant way to achieve it, I'll happily take it on board, if it has the same ease of use as forest.
    – Thev
    Nov 11, 2018 at 13:48
  • Why can't you just say e.g. [, \nodecirle, label=above:Nature, ...]?
    – cfr
    Nov 11, 2018 at 17:43

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.