3

I have created the following horizontal tree in LaTeX, using the forest package.

    \forestset{
  L1/.style={draw=black,},
  L2/.style={,edge={,line width=0.8pt}},
}

\begin{forest}
    for tree={
        grow=0,reversed, % tree direction
        parent anchor=east,child anchor=west, % edge anchors
        edge={line cap=round},outer sep=+1pt, % edge/node connection
        rounded corners,minimum width=15mm,minimum height=8mm, % node shape
        l sep=10mm % level distance
    }
  [Some text,L1
    [Some text ,L2]
    [Some text,L2]
    [Some text,L2]
  ]
\end{forest}

It gives me the following output:

enter image description here

Now I would like to "close" the tree again, i.e. the following:

enter image description here

Any input on how to modify the code so that the tree "grows together" at the end would be highly appreciated!

4

You can set names to the nodes in the tree and draw the merge node by hand.

\documentclass{article}
\usepackage{forest}
\forestset{
  L1/.style={draw=black,},
  L2/.style={,edge={,line width=0.8pt}},
}
\begin{document}
\begin{forest}
  for tree={
    grow=0,reversed, % tree direction
    parent anchor=east,child anchor=west, % edge anchors
    edge={line cap=round},outer sep=+1pt, % edge/node connection
    rounded corners,minimum width=15mm,minimum height=8mm, % node shape
    l sep=10mm % level distance
  }
  [Some text,L1
  [Some text ,L2,name=ST1]
  [Some text,L2,name=ST2]
  [Some text,L2,name=ST3]
  ]
  \node[draw,rounded corners,minimum width=15mm,minimum height=8mm,anchor=west] (EndNode) at ($(ST2.east) + (1,0)$){Merge text};
  \foreach \num in {1,2,3}{
    \draw (ST\num.east) -- (EndNode.west);
  }
\end{forest}
\end{document}

enter image description here

  • @Gret-D You don't actually have to name the nodes. You could just specify them relatively. – cfr Jun 21 '17 at 23:57
2

I think the best solution is to add the additional node as part of the tree and then add the additional edges, using that node's edge option. You can do this by naming nodes or, as here, using relative node names. You don't have to use the tikz key, but it simplifies matters if using relative node names as it means nodes are relative to whatever the current node happens to be. So () is the current node, (!u) is its parent, (!up) is its parent's previous sibling and so on. This means () edge ... will draw edges from 'here', wherever here happens to be.

\documentclass[border=10pt]{standalone}
\usepackage[linguistics]{forest}
\begin{document}
\tikzset{%
  L1/.style={draw=black},
  L2/.style={line width=0.8pt, line cap=round},
}%
\begin{forest}
  for tree={
    grow'=0,
    parent anchor=children,
    child anchor=parent,
    edge+=L2,
    outer sep=+1pt,
    rounded corners,
    minimum width=15mm,
    minimum height=8mm,
    l sep'=10mm,
  }
  [Some text, L1
    [Some text, L2]
    [Some text, L2
      [\phantom{Some text}, L1, tikz+/.process={Ow1{edge}{\draw [#1] (.child anchor) edge (!un.parent anchor) -- (!up.parent anchor);}}]
    ]
    [Some text, L2]
  ]
\end{forest}
\end{document}

symmetrical ending

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.