5

How can I put Dan, Eve, and Frank under the mother node? I tried changing anchor points and level distances but I couldn't put these children on the same horizontal level as the parent.

I prefer a solution that locally solves this problem, i.e., adding parameters to the nodes rather than changing the global settings of the forest, as I have a predefined macro based on this forest settings.

enter image description here

MWE:

\documentclass{article}
\usepackage{forest}
\begin{document}
\begin{forest}
for tree={  calign = first,
            grow=west,
            inner sep=0,
            outer sep=0,
            child anchor=east,
            l sep=5mm,
            s sep=8mm,
            anchor=north east
         }
[\begin{tabular}{l}A very wide and\\
tall parent node that\\ 
needs to have\\ 
its choldren surrounded\\
from left and bottom
\end{tabular}
 [Ann]
 [Bill]
 [Carl]
 [Dan]
 [Eve]
 [Frank]
]         
\end{forest}
\end{document}
6

If this is part of a larger tree, doing this with Forest is not unreasonable. If, however, your tree is limited to this structure, TikZ is a better option as you basically have to manually position the nodes anyway.

Note that tabular is never required in a Forest tree. Just use align=<tabular specification>. You get a tabular with align anyway.

\documentclass[border=10pt]{standalone}
\usepackage{forest}
\begin{document}
\begin{forest}
  for tree={
    calign child = 2,
    s sep'=8mm,
  },
  grow=-125,
  before drawing tree={
    for children={
      if={ > O_< {n}{4} }{x/.option=!u3.x}{y/.option=!u4.y}
    },
  },
  [A very wide and\\tallparent node that\\needs to be\\surrounded by its children\\from left and bottom, align=left
    [Ann]
    [Bill]
    [Carl]
    [Dan]
    [Eve]
    [Frank]
 ]         
\end{forest}
\end{document}

nodes positioned around root

You can adjust the angle of growth, calign child and/or s sep' as desired. If you don't want the order of the children reversed, use grow' rather than grow.

Personally, if this was the structure I needed, I'd be tempted to do something more like this:

nodes positioned around root alternatively designed

\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
  \node [align=center] (r) {A very wide and\\tall parent node that\\needs to be surrounded\\by its children from\\left and bottom};
  \foreach \i  [count=\j from 0, evaluate=\j as \k using {180+(18*\j)}] in {Ann,Bill,Carl,Dan,Eve,Frank} \draw (r) -- +(\k:30mm) node [anchor={180+\k}] {\i};
\end{tikzpicture}
\end{document}

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.