\documentclass{article}
\usepackage{tikz-qtree}
\begin{document}
\tikzset{edge from parent/.style=
{draw, edge from parent path={(\tikzparentnode.south)
-- +(0,-8pt)
-| (\tikzchildnode)}},
blank/.style={draw=none},
level distance=45pt}
\begin{tikzpicture}[every tree node/.style={align=center,minimum width=\widthof{Janet Botwood}}]
\Tree
[ .{Ruth Butler\\Registered Manager}
[ .{Anita Kaur\\Registered Manager} ]
[ .{Janet Botwood\\Head of Care} ]
[ .{Sunny Bell\\Head of Care} ] ]
\end{tikzpicture}
\end{document}
我试图让 Anita 和 Ruth 处于同一分支级别。另外,我该如何创建 Janet 和 Sunny 的子分支?
答案1
树不适用于多个“父母”。我不确定,如果我理解得对,但您可以将两个名字放入一个节点中:
% arara: pdflatex
\documentclass{article}
\usepackage{tikz-qtree}
\usetikzlibrary{shapes}
\begin{document}
\tikzset{edge from parent/.style=
{draw, edge from parent path={(\tikzparentnode.south)
-- +(0,-8pt)
-| (\tikzchildnode)}},
blank/.style={draw=none},
level distance=45pt}
\begin{tikzpicture}[every tree node/.style={align=center,minimum width=\widthof{Janet Botwood}}]
\Tree [.\node(grands)[rectangle split,rectangle split horizontal,rectangle split parts=2]{Ruth Butler\\Registered Manager \nodepart{second} Anita Kaur\\Registered Manager};
[ .{Janet Botwood\\Head of Care} A B C ]
[ .{Sunny Bell\\Head of Care} D E F ] ]
\end{tikzpicture}
\end{document}
答案2
像这样吗?
这使用了 powerforest
包。让 Ruth 和 Anita 处于同一级别的技巧是让她们成为某个phantom
节点的子节点,因为树必须有一个根。
\documentclass[tikz,border=5pt,multi]{standalone}
\usepackage{forest}
\begin{document}
\begin{forest}
for tree={
edge path={
\noexpand\path [draw, \forestoption{edge}] (!u.parent anchor) -- +(0,-5pt) -| (.child anchor)\forestoption{edge label};
},
align=center,
parent anchor=south,
child anchor=north
}
[, phantom, for children={fit=band}
[Ruth Butler\\Registered Manager
[Janet Botwood\\Head of Care
[child 1]
[child 2]
[child 3]
]
[Sunny Bell\\Head of Care
[child 1]
[child 2]
[child 3]
]
]
[Anita Kaur\\Registered Manager]
]
\end{forest}
\end{document}
或者像这样?
\documentclass[tikz,border=5pt,multi]{standalone}
\usepackage{forest}
\begin{document}
\begin{forest}
for tree={
edge path={
\noexpand\path [draw, \forestoption{edge}] (!u.parent anchor) -- +(0,-5pt) -| (.child anchor)\forestoption{edge label};
},
align=center,
parent anchor=south,
child anchor=north
}
[, phantom, for children={fit=band}
[Ruth Butler\\Registered Manager
[Janet Botwood\\Head of Care
[child 1]
[child 2]
[child 3]
]
]
[Anita Kaur\\Registered Manager
[Sunny Bell\\Head of Care
[child 1]
[child 2]
[child 3]
]
]
]
\end{forest}
\end{document}