3

I am working to create THIS but cannot add the red box. There are more other modifications I am working to include: arrows instead of lines, a caption, and more space so the boxes are not cut. Here is my code so far!

\documentclass{standalone}
\usepackage{forest}
\begin{document}
\begin{forest} 
for tree={
    draw=black, align=center, l sep=4ex, parent anchor=south, child anchor=north,
    node options={font=\footnotesize, minimum width=14em, minimum height=10ex},
    edge path={
        \noexpand\path[\forestoption{edge}]
        (!u.parent anchor) -- +(0,-2ex) -| (.child anchor)\forestoption{edge label};
    }
}
[Parent
        [Child2
            [Child21]
            [Child22]           
            [Child23,name=Child23]]]]
\end{forest}
\end{document}
2
\documentclass[tikz,border=3.14pt]{standalone}
\usepackage{forest}
\usetikzlibrary{positioning}
\begin{document}
\begin{forest} 
for tree={
    draw=black, align=center, l sep=4ex, parent anchor=south, child anchor=north,
    node options={font=\footnotesize, minimum width=14em, minimum height=10ex},
    edge path={
        \noexpand\path[\forestoption{edge}]
        (!u.parent anchor) -- +(0,-2ex) -| (.child anchor)\forestoption{edge label};
    }
}
[Parent,name=Parent
        [Child2
            [Child21]
            [Child22]           
            [Child23,name=Child23]]]]
\node[right=2cm of Parent,draw, minimum width=14em, minimum
height=10ex,red](Stepfather){};         
\draw[red] (Stepfather) -- (Parent);
\end{forest}
\end{document}

enter image description here

| improve this answer | |
2

Here's a method which adds the node as part of the tree, using a fake root. For complex cases, this approach tends to be easier, although it certainly isn't necessary here.

I recommend updating your code to use Forest's edges library, however, and more flexible anchor specifications. arrows.meta can be used to add fancy arrow tips to your edges.

\documentclass[border=10pt]{standalone}
\usepackage[edges]{forest}
\usetikzlibrary{arrows.meta}
\begin{document}
\begin{forest} 
  forked edges,
  for tree={
    draw=black,
    align=center,
    l sep'=4ex,
    parent anchor=children,
    child anchor=parent,
    font=\footnotesize, 
    minimum width=14em, 
    minimum height=10ex,
    edge+={-Latex},
  }
  [, coordinate
    [Parent, no edge
      [Child2
        [Child21]
        [Child22]           
        [Child23]]]
      [, draw=red, before computing xy={s'+=10mm}, edge+={red}, edge path'={(!s) -- ()}]
  ]
\end{forest}
\end{document}

modified tree

| improve this answer | |
  • I agree that one can learn more from your code. (+1 ;-) – user121799 Apr 18 '18 at 2:42
  • @marmot I don't know about more, but sometimes the tikz and relative name thing is easier. (Especially, you can make styles this way to avoid replicating code for similar constructions each time.) – cfr Apr 18 '18 at 3: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.