
是否可以使用森林包種植一棵樹,以便子級垂直堆疊,如下所示:
我最終這樣做了:如果父母是 A 並且有三個孩子 BCD,並且我想附加所有孩子,如上所示,我必須這樣做:
\begin{forest}
for tree={
draw,
% minimum height=2cm,
% anchor=west,
align=center
% calign
% child anchor=west
},
[{ROOT}, align=center
[{ A} , parent anchor=south, child anchor=north
[{B}, parent anchor=east, anchor=east, child anchor=east , calign=child edge
[{C}, parent anchor=east, anchor=east, child anchor=east, calign=child edge
[{D}, parent anchor=east, anchor=east, child anchor=east
]
]
]
]
\end{forest}
正如您所看到的,即使它們都是 A 的子級,我也必須將 B 設為 C 的父級,將 C 設為 D 的父級。
答案1
不僅之前有幾個人提供了該圖的程式碼,而且我之前也確實使用 Forest 回答過它。
如果問題中的圖像與來源相關聯,那就容易多了,因為這很可能會給我一個線索。
我知道我已經給了森林解決方案,因為我找到了一個,但我似乎沒有給出我的答案的連結。我記得我很惱火,因為當OP可以連結到我可以複製貼上和改編的程式碼時,我從頭開始繪製了圖表,因為它之前已經得到了回答(但也許程式碼不再工作或沒有使用Forest或某物) 。
這張圖非常煩人,因為這種情況不斷發生在我身上。
無論如何,我使用程式碼的修改版本更新了 Forest v.2 的程式碼我的答案連結到托比昂 T. 的評論。此版本使用庫folder
中的樣式edges
。
\documentclass[border=5pt,tikz,multi]{standalone}
\usepackage[edges]{forest}
\usetikzlibrary{arrows.meta,shadows.blur}
\forestset{%
colour me out/.style={outer color=#1!75, inner color=#1!50, draw=darkgray, thick, blur shadow, rounded corners},
rect/.append style={rectangle, rounded corners=2pt},
dir tree switch/.style args={at #1}{%
for tree={
edge=-Latex,
font=\sffamily,
fit=rectangle,
},
where level=#1{
for tree={
folder,
grow'=0,
},
delay={child anchor=north},
}{},
before typesetting nodes={
for tree={
content/.wrap value={\strut ##1},
},
if={isodd(n_children("!r"))}{
for nodewalk/.wrap pgfmath arg={{fake=r,n=##1}{calign with current edge}}{int((n_children("!r")+1)/2)},
}{},
},
},
}
\begin{document}
\begin{forest}
dir tree switch=at 1,
for tree={
font=\sffamily\bfseries,
rect,
align=center,
edge+={thick, draw=darkgray},
where level=0{%
colour me out=green!50!white,
}{%
if level=1{%
colour me out=green!95!black,
}{%
colour me out=magenta!50!orange!75!white,
edge+={-Triangle},
},
},
}
[Drawing\\Diagrams
[Defining node\\and arrow styles
[Setting shape]
[Choosing colour]
[Adding shading]
]
[Positioning\\the nodes
[Using a matrix
[Absolutely]
[Relatively]
[Using overlays]
]
]
[Drawing arrows\\between nodes
[Default arrows
[Arrow library]
[Re-sizing tips]
[Shortening]
[Bending]
]
]
]
\end{forest}
\end{document}