ฉันจะวาดแผนผังต้นไม้ที่ใบไม้เชื่อมต่อกับกิ่งก้านที่บรรจบกันได้อย่างไร

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}

ฉันจะเชื่อมต่อสาขาทั้งหมดตามที่แสดงด้านล่างในภาพร่างได้อย่างไร

คำตอบ

3 AndréC Aug 16 2020 at 16:29

อัปเดต 2: ลูกศรระหว่างโหนดที่มีข้อกำหนดทางเดิน

ลูกศรเพิ่มเติมทั้งหมด(ไม่ได้สร้างขึ้นโดยฟอเรสต์)ที่เชื่อมต่อสองโหนดจะถูกวางไว้ในแผนภูมิด้วยไวยากรณ์การเดินโหนด นี้โดยไม่ต้องตั้งชื่อโหนดเป็นมาก่อน(การออกกำลังกายรูปแบบจริง) เพื่อที่จะช่วยให้การมองเห็นของลูกศรเหล่านี้ผมสีพวกเขาในสีแดง

ฉันอ้างคู่มือ:

Nodewalk เป็นวิธีที่กระชับในการแสดงความสัมพันธ์ของโหนด มันเป็นเพียงสตริงของขั้นตอนซึ่งแสดงด้วยอักขระเดี่ยวโดยที่: uย่อมาจากโหนดแม่ (ขึ้น); pสำหรับพี่น้องคนก่อนหน้า; nสำหรับพี่น้องคนต่อไป sสำหรับพี่น้อง (มีประโยชน์เฉพาะในต้นไม้ไบนารี); 1 , 2 , . . 9สำหรับครั้งแรกวินาที . . ลูกคนที่เก้า; ลิตรสำหรับเด็กคนสุดท้าย ฯลฯ สำหรับคุณสมบัติที่สมบูรณ์ให้ดูที่ส่วน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}

เพื่อตอบสนองต่อการอัปเดต

ฉันได้ทำการซ่อมแซมมากมายเพื่อให้ได้ผลลัพธ์นี้ดังนั้นฉันจึงไม่แน่ใจว่าฉันเขียนโค้ดอย่างหรูหรา หากผู้เชี่ยวชาญด้านป่าไม้มาด้วยฉันยินดีรับฟังสิ่งที่สามารถปรับปรุงได้

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

คำตอบเก่า

อาจมีทางออกที่หรูหรากว่านี้ แต่นี่คือข้อเสนอของฉัน

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