Wie kann ich ein Baumdiagramm zeichnen, in dem Blätter mit konvergierenden Zweigen verbunden sind?

Aug 16 2020
\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}

Wie könnte ich alle Zweige auf die unten in der Skizze gezeigte Weise verbinden?

Antworten

3 AndréC Aug 16 2020 at 16:29

Update 2: Pfeile zwischen Knoten mit Nodewalk-Spezifikation

Alle zusätzlichen Pfeile (nicht nativ von Gesamtstruktur erstellt) , die zwei Knoten verbinden, werden mit der Short Node Walk- Syntax im Baum platziert . Dies ohne die Knoten wie zuvor zu benennen (eine echte Stilübung) . Um diese Pfeile sichtbar zu machen, habe ich sie rot gefärbt .

Ich zitiere das Handbuch:

Ein Nodewalk ist eine übersichtliche Möglichkeit, Knotenbeziehungen auszudrücken. Es ist einfach eine Folge von Schritten, die durch einzelne Zeichen dargestellt werden, wobei: u für den übergeordneten Knoten steht (aufwärts); p für das vorherige Geschwister; n für das nächste Geschwister; s für das Geschwister (nützlich nur in Binärbäumen); 1 , 2 ,. . . 9 für erste, zweite ,. . . neuntes Kind; l, für das letzte Kind usw. Die vollständige Spezifikation finden Sie in Abschnitt 3.8.7 .

\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}

Als Antwort auf ein Update

Ich habe viel gebastelt, um dieses Ergebnis zu erzielen, und bin mir daher nicht sicher, ob ich elegant codiert habe. Wenn ein Waldexperte vorbeikommt, höre ich mir an, welche Verbesserungen vorgenommen werden können.

\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}

Alte Antwort

Es mag eine elegantere Lösung geben, aber hier ist mein Vorschlag.

\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}