2
\documentclass{article}
\usepackage{fullpage}
\usepackage[utf8]{inputenc}
\usepackage{tikz}
\usetikzlibrary{arrows,shapes,positioning,shadows,trees}
\usetikzlibrary{arrows.meta}
\usepackage{mdframed}
\usepackage{boxedminipage}
\usepackage{forest}

\begin{document}

\begin{forest}
% Styling
for tree={
align=center,
parent anchor=south,
child anchor=north,
edge={thick, -{Stealth[]}},
l sep+=10pt,
edge path={
\noexpand\path [draw, \forestoption{edge}] (!u.parent anchor) -- +(0,-10pt) -| (.child anchor)\forestoption{edge label};
},
if level=0{
inner xsep=-15pt,
tikz={\draw [thick] (.south east) -- (.south west);}
}{}
}
%
[Alphabet
[a
[b]
[c] ]
[b
[d]
[e] ]
]
\end{forest}

\end{document}

How would I be able to connect all the branches in the manner shown below in the sketch

enter image description here enter image description here

TobiBS
  • 5,240
  • 1
    it would be helpful to place a handrawn sketch of the requirement – js bibra Aug 16 '20 at 02:23
  • 1
    Welcome to TeX.SE. By joining the leaves, your diagram is no longer a tree. As discussed here: Lost in the Forest — Merging after Branching? there are other ways of drawing such structures. As that answer shows, a solution using Forest is possible, but it does involve learning syntax specific to Forest. It might be better to adopt the matrix of nodes approach and learn basic TikZ syntax that can then be extended to many other applications. – Ross Aug 16 '20 at 03:33
  • Please give a clearer specification of what you want — a simple sketch would be ideal, as @js_bibra suggests. Currently the question is essentially unanswerable: I can imagine half a dozen very different looking arrangements that could fit your description. – Peter LeFanu Lumsdaine Aug 16 '20 at 09:41
  • Sketch Provided Above. – Syed Asad Haroon Aug 16 '20 at 15:14

1 Answers1

4

Update 2: Arrows between nodes with nodewalk specification

All additional arrows (not built natively by forest) that connect two nodes are placed in the tree with the short node walk syntax. This without naming the nodes as before (a real style exercise). In order to allow the visualization of these arrows, I colored them in red.

I quote the manual:

A nodewalk is a concise way of expressing node relations. It is simply a string of steps, which are represented by single characters, where: u stands for the parent node (up); p for the previous sibling; n for the next sibling; s for the sibling (useful only in binary trees); 1, 2, . . . 9 for first, second, . . . ninth child; l, for the last child, etc. For the complete specification, see section 3.8.7.

with nodewalk

\documentclass[border=5mm]{standalone}
\usepackage{forest}
\usetikzlibrary{arrows.meta}
\useforestlibrary{linguistics}

\begin{document} \begin{forest} % Styling for tree={ align=center, parent anchor=south, child anchor=north, edge={thick, -{Stealth[]}}, l sep+=10pt, edge path={\noexpand\path [draw, \forestoption{edge}] (!u.parent anchor) -- +(0,-10pt) -| (.child anchor)\forestoption{edge label}; }, if level=0{inner xsep=-15pt,tikz={\draw [thick] (.south east) -- (.south west);} }{} } % [Alphabet [a [b] [c,s sep=10, [f,s sep=30, [,phantom] [z,edge={white}] {\draw[thick,red,-{Stealth[]}] (!rllN.south east) -- +(0,-10pt) -| (!c); %<-- arrow from g to z \draw[thick,red] (!uss.south west) -- +(0,-10pt) -| (!c) ;%<-- arrow from f to z } ]{\draw[thick,red,shorten >=3pt] (!us.south) -- +(0,-10pt) -| (!c) ;}%<-- arrow from b to f [,phantom]
] ] [b [d] [e,s sep=9 [g]{\draw[thick,red,shorten >=3pt] (!us.south) -- +(0,-10pt) -| (!c) ;}%<-- arrow from d to g [,phantom]
] ] ] \end{forest}

\end{document}

In response to an update

I've done a lot of tinkering to achieve this result and so I'm not sure I coded elegantly. If a forest expert comes by, I'm listening to what improvements can be made.

screenshot

\documentclass[border=5mm]{standalone}
\usepackage{forest}
\usetikzlibrary{arrows.meta}
\useforestlibrary{linguistics}

\begin{document} \begin{forest} % Styling for tree={ align=center, parent anchor=south, child anchor=north, edge={thick, -{Stealth[]}}, l sep+=10pt, edge path={\noexpand\path [draw, \forestoption{edge}] (!u.parent anchor) -- +(0,-10pt) -| (.child anchor)\forestoption{edge label}; }, if level=0{inner xsep=-15pt,tikz={\draw [thick] (.south east) -- (.south west);} }{} } % [Alphabet [a [b,name=b] [c,s sep=10, [f,name=f,s sep=30, [,phantom] [z,name=z,edge={white}] ] [,phantom]
] ] [b [d,name=d] [e,s sep=9 [g,name=g] [,phantom]
] ] ] \draw[thick,shorten >=2pt] (b.south) -- +(0,-10pt) -| (f.north); \draw[thick,shorten >=2pt] (d.south) -- +(0,-10pt) -| (g.north); \draw[thick,shorten >=2pt] (g.south east) -- +(0,-10pt) -| (z.north); \draw[thick,-{Stealth[]}] (f.south west) -- +(0,-10pt) -| (z.north); \end{forest}

\end{document}

Old answer

There may be a more elegant solution, but here is my proposal.

screenshot

\documentclass[border=5mm]{standalone}
\usepackage{forest}
\usetikzlibrary{arrows.meta}
\useforestlibrary{linguistics}
%\usepackage{fullpage}
%\usepackage[utf8]{inputenc}
%\usepackage{tikz}
%\usetikzlibrary{arrows,shapes,positioning,shadows,trees}
%\usepackage{mdframed}
%\usepackage{boxedminipage}

\begin{document} \begin{forest} % Styling for tree={ align=center, parent anchor=south, child anchor=north, edge={thick, -{Stealth[]}}, l sep+=10pt, edge path={\noexpand\path [draw, \forestoption{edge}] (!u.parent anchor) -- +(0,-10pt) -| (.child anchor)\forestoption{edge label}; }, if level=0{inner xsep=-15pt,tikz={\draw [thick] (.south east) -- (.south west);} }{} } % [Alphabet [a [b,name=b] [c,name=c [,phantom] [z,name=z] ] ] [b [d,name=d] [e,name=e] ] ] \draw[thick,shorten >=2pt] (b.south) -- +(0,-10pt) -| (z.north); \draw[thick,shorten >=2pt] (d.south) -- +(0,-10pt) -| (z.north); \draw[thick,shorten >=2pt] (e.south) -- +(0,-10pt) -| (z.north); \end{forest}

\end{document}

AndréC
  • 24,137
  • Thanks, Andre. What would be the adjusted MWE if I were to request the above-edited sketch? – Syed Asad Haroon Aug 16 '20 at 14:39
  • Yours is not too bad, just remove the packages that are not used, everything is very well explained here. How to make a “minimum example” – AndréC Aug 16 '20 at 14:47
  • Cheers, and how would I be able to produce the sketch I just added above? Apologies as I am new to learning the forest package. – Syed Asad Haroon Aug 16 '20 at 14:51
  • 1
    I don't know this package very well myself (I never use it personally). I spent a lot of time this morning trying to understand the syntax, which is not trivial (whatever the specialists say). I'm thinking about your update. Let's hope that a forest specialist answers before me, because it will take me some time. I want you to know that I voted for your question because I always vote for the questions that have interested me so much that I think about them and write an answer. – AndréC Aug 16 '20 at 14:59