这个问题建立在上一个问题我在这里发帖。
以下代码:
\documentclass[tikz,border=10pt]{standalone}
\usepackage{forest}
\usetikzlibrary{arrows.meta, shapes.geometric, calc, shadows}
\colorlet{mygreen}{green!75!black}
\colorlet{col1in}{red!30}
\colorlet{col1out}{red!40}
\colorlet{col2in}{mygreen!40}
\colorlet{col2out}{mygreen!50}
\colorlet{col3in}{blue!30}
\colorlet{col3out}{blue!40}
\colorlet{col4in}{mygreen!20}
\colorlet{col4out}{mygreen!30}
\colorlet{col5in}{blue!10}
\colorlet{col5out}{blue!20}
\colorlet{col6in}{blue!20}
\colorlet{col6out}{blue!30}
\colorlet{col7out}{orange}
\colorlet{col7in}{orange!50}
\colorlet{col8out}{orange!40}
\colorlet{col8in}{orange!20}
\colorlet{linecol}{blue!60}
\begin{document}
\pgfkeys{/forest,
rect/.append style = {rectangle, rounded corners = 2pt,
inner color = col6in, outer color = col6out},
ellip/.append style = {ellipse, inner color = col5in,
outer color = col5out},
orect/.append style = {rect, font = \sffamily\bfseries\LARGE,
text width = 325pt, text centered,
minimum height = 10pt, outer color = col7out,
inner color=col7in},
oellip/.append style = {ellip, inner color = col8in, outer color = col8out,
font = \sffamily\bfseries\large, text centered}}
\begin{forest}
for tree={
font=\sffamily\bfseries,
line width=1pt,
draw=linecol,
ellip,
align=center,
child anchor=north,
parent anchor=south,
drop shadow,
l sep'+=12.5pt,
edge+={color=linecol, rounded corners=5pt, >={Stealth[length=10pt]}, line width=1pt, ->},
edge path'={(!u.parent anchor) -- +(0,-5pt) -| (.child anchor)},
}
[Start, inner color=col1in, outer color=col1out,name=rootNode
[X1, inner color=col2in, outer color=col2out, name=X1
[A longer string, rect, name=Y1
[Short, rect, name=Z1
]
[Short, rect, name=Z2
]
[Short, rect, name=Z3
]
[Short, rect, name=Z4
]
[Short, rect, name=Z5
]
[Short, rect, name=Z6
]
[Short, rect, name=Z7
]
[Short, rect, name=Z8
]
]
[A longer string, rect, name=Y2
]
[A longer string, rect, name=Y3
]
[A longer string, rect, name=Y4
]
[A longer string, rect, name=Y5
]
[A longer string, rect, name=Y6
]
[A longer string, rect, name=Y7
]
[A longer string, rect, name=Y8
]
]
[X2, inner color=col3in, outer color=col3out,name=X2
]
]
\begin{scope}[color = linecol, rounded corners = 5pt, >={Stealth[length=10pt]}, line width=1pt, ->]
\draw (X2.parent anchor) -- +(0,-5pt) -| (Y1.child anchor);
\draw (Y1.parent anchor) -- +(0,-5pt) -| (Z1.child anchor);
\draw (Y2.parent anchor) -- +(0,-5pt) -| (Z2.child anchor);
\draw (Y3.parent anchor) -- +(0,-5pt) -| (Z3.child anchor);
\draw (Y4.parent anchor) -- +(0,-5pt) -| (Z4.child anchor);
\draw (Y5.parent anchor) -- +(5pt,-5pt) -| (Z1.child anchor);
\draw (Y6.parent anchor) -- +(0,-5pt) -| (Z1.child anchor);
\draw (Y7.parent anchor) -- +(0,-5pt) -| (Z1.child anchor);
\draw (Y8.parent anchor) -- +(0,-5pt) -| (Z1.child anchor);
\end{scope}
\end{forest}
\end{document}
产生以下输出:
但是,这太偏左了。我希望有一个居中输出,这样输出图的每一行都与父行对齐。非常感谢您的帮助。
答案1
\documentclass[tikz,border=10pt]{standalone}
\usepackage{forest}
\usetikzlibrary{arrows.meta, shapes.geometric, calc, shadows}
\colorlet{mygreen}{green!75!black}
\colorlet{col1in}{red!30}
\colorlet{col1out}{red!40}
\colorlet{col2in}{mygreen!40}
\colorlet{col2out}{mygreen!50}
\colorlet{col3in}{blue!30}
\colorlet{col3out}{blue!40}
\colorlet{col4in}{mygreen!20}
\colorlet{col4out}{mygreen!30}
\colorlet{col5in}{blue!10}
\colorlet{col5out}{blue!20}
\colorlet{col6in}{blue!20}
\colorlet{col6out}{blue!30}
\colorlet{col7out}{orange}
\colorlet{col7in}{orange!50}
\colorlet{col8out}{orange!40}
\colorlet{col8in}{orange!20}
\colorlet{linecol}{blue!60}
\begin{document}
\pgfkeys{/forest,
rect/.append style = {rectangle, rounded corners = 2pt,
inner color = col6in, outer color = col6out},
ellip/.append style = {ellipse, inner color = col5in,
outer color = col5out},
orect/.append style = {rect, font = \sffamily\bfseries\LARGE,
text width = 325pt, text centered,
minimum height = 10pt, outer color = col7out,
inner color=col7in},
oellip/.append style = {ellip, inner color = col8in, outer color = col8out,
font = \sffamily\bfseries\large, text centered}}
\begin{forest}
for tree={
font=\sffamily\bfseries,
line width=1pt,
draw=linecol,
ellip,
align=center,
child anchor=north,
parent anchor=south,
drop shadow,
l sep'+=12.5pt,
edge+={color=linecol, rounded corners=5pt, >={Stealth[length=10pt]}, line width=1pt, ->},
edge path'={(!u.parent anchor) -- +(0,-5pt) -| (.child anchor)},
}
[Start, inner color=col1in, outer color=col1out,name=rootNode
[X1, inner color=col2in, outer color=col2out, name=X1
[A longer string, rect, name=Y1
]
[A longer string, rect, name=Y2
]
[A longer string, rect, name=Y3
]
[A longer string, rect, name=Y4
[Short, rect, name=Z1
]
[Short, rect, name=Z2
]
[Short, rect, name=Z3
]
[Short, rect, name=Z4
]
[Short, rect, name=Z5
]
[Short, rect, name=Z6
]
[Short, rect, name=Z7
]
[Short, rect, name=Z8
]]
[A longer string, rect, name=Y5
]
[A longer string, rect, name=Y6
]
[A longer string, rect, name=Y7
]
[A longer string, rect, name=Y8
]
]
[X2, inner color=col3in, outer color=col3out,name=X2
]
]
\begin{scope}[color = linecol, rounded corners = 5pt, >={Stealth[length=10pt]}, line width=1pt, ->]
\draw (X2.parent anchor) -- +(0,-5pt) -| (Y1.child anchor);
\draw (Y1.parent anchor) -- +(0,-5pt) -| (Z1.child anchor);
\draw (Y2.parent anchor) -- +(0,-5pt) -| (Z2.child anchor);
\draw (Y3.parent anchor) -- +(0,-5pt) -| (Z3.child anchor);
\draw (Y4.parent anchor) -- +(0,-5pt) -| (Z4.child anchor);
\draw (Y5.parent anchor) -- +(5pt,-5pt) -| (Z1.child anchor);
\draw (Y6.parent anchor) -- +(0,-5pt) -| (Z1.child anchor);
\draw (Y7.parent anchor) -- +(0,-5pt) -| (Z1.child anchor);
\draw (Y8.parent anchor) -- +(0,-5pt) -| (Z1.child anchor);
\end{scope}
\end{forest}
\end{document}