我想要的是有三个节点水平对齐(根 1SA、第一级子节点“0--7 HL”和第二级子节点“各种分布4”),并且具有具有相同 y 坐标的直线连接器,以便它们看起来像一条直线。
梅威瑟:
\RequirePackage{tikz}
\usetikzlibrary{fit, positioning, shapes, trees}
\RequirePackage[edges]{forest}
\documentclass{article}
\begin{document}
\begin{forest}
for tree={rounded corners,
grow'=0, l=0, l sep=2em,
child anchor=west, anchor=west,
parent anchor=east,
tier/.pgfmath=level(),
shape=rectangle, rounded corners, draw=red, align=left, top color=white, bottom color=blue!20, minimum width = 2mm, minimum height = 4mm,
edge path={\noexpand\path[\forestoption{edge}](!u.parent anchor)|-(.child anchor)\forestoption{edge label};},
}
[{1SA}, calign=child, calign child=2
[{0--7 HL}
[{\underline{\textbf{Various distributions1}}\\Stayman Takis} ]
[{\underline{\textbf{Various distributions2}}\\Texas} ]
[{\underline{\textbf{Various distributions3}}\\Stayman normal, if a single major\\Texas, otherwise} ]
[{\underline{\textbf{Various distributions4}}\\Pass, with bad suit\\Texas, otherwise} ]
[{\underline{\textbf{Various distributions5}}\\Pass, 0--4 HL\\Texas M 5--7 HL} ]
[{\underline{\textbf{Various distributions6}}\\Pass, 0--4 HL\\Texas M 5--7 HL} ]
[{\underline{\textbf{Various distributions7}}\\Pass} ]
]
]
\end{forest}
\end{document}
答案1
要获得水平对齐,calign=child
还需要为第二级指定。在下面的代码中,我只是为整个树设置了它。
实际上,代码设置了calign=child edge
。即使child/parent anchor
与不同,这也会产生所需的结果anchor
。(calign=child
对齐 anchor
s,而calign=child edge
对齐parent anchor
和child anchor
。)
我还包括了中间孩子的自动计算:calign child=(n_children()+1)/2
。(也许有calign=mid-child
和calign=mid-child edge
并不是一个坏主意?)
\RequirePackage{tikz}
\usetikzlibrary{fit, positioning, shapes, trees}
\RequirePackage[edges]{forest}
\documentclass{article}
\begin{document}
\begin{forest}
for tree={rounded corners,
grow'=0, l=0, l sep=2em,
child anchor=west, anchor=west,
parent anchor=east,
tier/.pgfmath=level(),
shape=rectangle, rounded corners, draw=red, align=left, top color=white, bottom color=blue!20, minimum width = 2mm, minimum height = 4mm,
edge path={\noexpand\path[\forestoption{edge}](!u.parent anchor)|-(.child anchor)\forestoption{edge label};},
calign=child edge, calign child=(n_children()+1)/2,
}
[{1SA},
[{0--7 HL},
[{\underline{\textbf{Various distributions1}}\\Stayman Takis} ]
[{\underline{\textbf{Various distributions2}}\\Texas} ]
[{\underline{\textbf{Various distributions3}}\\Stayman normal, if a single major\\Texas, otherwise} ]
[{\underline{\textbf{Various distributions4}}\\Pass, with bad suit\\Texas, otherwise} ]
[{\underline{\textbf{Various distributions5}}\\Pass, 0--4 HL\\Texas M 5--7 HL} ]
[{\underline{\textbf{Various distributions6}}\\Pass, 0--4 HL\\Texas M 5--7 HL} ]
[{\underline{\textbf{Various distributions7}}\\Pass} ]
]
]
\end{forest}
\end{document}