我正在寻找存在的问题和讨论
\documentclass[tikz,border=10pt]{standalone}
\usepackage[edges]{forest}
\usetikzlibrary{arrows.meta,shadows.blur}
\begin{document}
\colorlet{myyellow}{yellow!50}
\begin{forest}
colour me/.style={top color=#1!75, bottom color=#1, draw=#1, thick, blur shadow, rounded corners},
for tree={
edge=-Latex,
font=\sffamily,
},
where level=1{
for tree={
folder,
grow'=0,
},
edge path'={(!u.parent anchor) -- ++(0,-15pt) -| (.child anchor)},
}{},
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)},
}{},
tempcounta/.max={level}{tree},
for tree={
colour me/.wrap pgfmath arg={cyan!#1!myyellow}{100*((tempcounta)-level())/(tempcounta)}
}
}
[Project Plan
[Objective-A
[A1]
[A2]
[A3]
[A4]
]
[Objective-B
[B1]
[B2]
[B3]
[B4[Extra]]
[ \hspace{0.0cm} Data Analysis, no edge, colour me=red]
]
[Objective-C
[C1]
[C2]
[C3]
[C4]
[C5]
]
[Objective-D
[D1]
[D2]
[D3]
[D4]
]
]
\end{forest}
\end{document}
答案1
您不能将它们添加到树规范中,因为它们会使其成为非树,但您可以使用常规 Ti钾Z 来添加它们,也可以通过tikz
键添加。
\documentclass[tikz,border=10pt]{standalone}
\usepackage[edges]{forest}
\usetikzlibrary{arrows.meta,shadows.blur}
\begin{document}
\colorlet{myyellow}{yellow!50}
\begin{forest}
colour me/.style={top color=#1!75, bottom color=#1, draw=#1, thick, blur shadow, rounded corners},
for tree={edge=-Latex, font=\sffamily,},
where level=1{
for tree={folder, grow'=0, },
edge path'={(!u.parent anchor) -- ++(0,-15pt) -| (.child anchor)},
if nodewalk valid={p}{tikz+={\draw [-Latex] (!p) -- (); } }{},
}{},
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)},
}{},
tempcounta/.max={level}{tree},
for tree={
colour me/.wrap pgfmath arg={cyan!#1!myyellow}{100*((tempcounta)-level())/(tempcounta)}
},
},
[Project Plan
[Objective-A, tikz+={\draw [-Latex] (.west) -- ++(-5pt,0) |- (da.west); }
[A1]
[A2]
[A3]
[A4]
]
[Objective-B
[B1]
[B2]
[B3]
[B4[Extra]]
[Data Analysis, no edge, colour me=red, name=da]
]
[Objective-C
[C1]
[C2]
[C3]
[C4]
[C5]
]
[Objective-D, tikz+={\draw [-Latex] (.east) -- ++(5pt,0) |- (da.east); }
[D1]
[D2]
[D3]
[D4]
]
]
\end{forest}
\end{document}
编辑
如果您希望根节点更加集中,您可以将其置于第一个和最后一个子节点之间或第二个和第三个子节点之间。此代码采用前一种选择,但可以轻松调整以实现后者。
\documentclass[tikz,border=10pt]{standalone}
\usepackage[edges]{forest}
\usetikzlibrary{arrows.meta,shadows.blur}
\begin{document}
\colorlet{myyellow}{yellow!50}
\begin{forest}
colour me/.style={top color=#1!75, bottom color=#1, draw=#1, thick, blur shadow, rounded corners},
for tree={edge=-Latex, font=\sffamily,},
where level=1{
for tree={folder, grow'=0, },
edge path'={(!u.parent anchor) -- ++(0,-15pt) -| (.child anchor)},
if nodewalk valid={p}{tikz+={\draw [-Latex] (!p) -- (); } }{},
}{},
before typesetting nodes={
for tree={content/.wrap value={\strut #1},},
if={isodd(n_children("!r"))}{
for nodewalk/.process={Ow+nw{!r.n children}{(#1+1)/2}{fake=r,n=#1}{calign with current edge}},
}{},
tempcounta/.max={level}{tree},
for tree={
colour me/.process={ROw2+Pw{tempcounta}{level}{100*(#1-#2)/#1}{cyan!#1!myyellow}},
},
},
before drawing tree={%
tempdima'=0pt,
for nodewalk={
fake=r, 1, tempdima/.option=x, tempdima+/.option=min x, fake=r, l, tempdima+/.option=x, tempdima+/.option=max x
}{},
tempdima*=.5,
x/.register=tempdima,
}
[Project Plan,
[Objective-A, tikz+={\draw [-Latex] (.west) -- ++(-5pt,0) |- (da.west); }
[A1]
[A2]
[A3]
[A4]
]
[Objective-B
[B1]
[B2]
[B3]
[B4[Extra]]
[Data Analysis, no edge, colour me=red, name=da]
]
[Objective-C
[C1]
[C2]
[C3]
[C4]
[C5]
]
[Objective-D, tikz+={\draw [-Latex] (.east) -- ++(5pt,0) |- (da.east); }
[D1]
[D2]
[D3]
[D4]
]
]
\end{forest}
\end{document}