我想使用 tikz 包绘制树形图(请参阅下面到目前为止的代码)。我的问题是所有节点都限制在它们自己的矩阵列中,因此我的图变得太宽,无法放在一页上,而且总体上看起来不太好看。相反,我希望节点重叠,例如,我图最上层的节点不仅应限制在第 4 列,还应占据第 3 列和第 5 列的部分。有什么想法可以实现吗?
为了清楚起见,这里是我在网上找到的一张具有重叠节点的树形图: http://thepeakperformancecenter.com/wp-content/uploads/2017/03/Tree-Diagram.jpg[][1]
以下是我目前编写的代码:
\begin{tikzpicture}
\matrix (m) [
matrix of nodes,
nodes={draw},
column sep=1mm,
row sep=12mm,
] {
& & & Does the wave function collapse? & & & \\
& Is the collapse spontaneous or produced externally? & & & & Are there hidden variables? & \\
Von Neumann & & GRW & & Many Worlds & & Bohm \\
};
\begin{scope}[
font=\footnotesize,
inner sep=.25em,
line cap=round,
]
\newcommand*{\LINE}[4][.5]{%
\path (m-#2) -- node[pos=#1] (tmp) {$#4$} (m-#3);
\draw (m-#2) -- (tmp) -- (m-#3);
}
\LINE {1-4}{2-2}{Yes}
\LINE[.7] {1-4}{2-6}{No}
\LINE{2-2} {3-1}{External}
\LINE {2-2}{3-3}{Spontaneous}
\LINE {2-6}{3-5}{Yes}
\LINE {2-6}{3-7}{No}
\end{scope}
\end{tikzpicture}
答案1
我猜你喜欢这样的东西:
这棵树是使用forest
包(专用于绘制树形图)绘制的。我还将一个节点中的长文本分成两行:
\documentclass[margin=3mm]{standalone}
\usepackage{forest}
\begin{document}
\begin{forest}
for tree = {draw,
align=center,
anchor=north,
s sep=5mm, % horizontal distance between nodes
l sep=7mm, % vertical distance between nodes
tier/.option=level,
EL/.style = {edge label={node[midway, fill=white, inner sep=2pt,
font=\footnotesize\itshape, anchor=center,
text depth=0.3ex]{#1}},
}% edge labels style
}
%
[Does the wave function collapse?
[Is the collapse spontaneous\\ or produced externally?,EL=Yes
[Von Neumann,EL=External]
[GRW,EL=Spotaneous]
]
[Are there hidden variables?,EL=No
[Many Worlds,EL=Yes]
[Bohm,EL=No]
]
]
\end{forest}
\end{document}
编辑:唉,我忘了边缘标签。现在它们被添加了
编辑(2):增加了遗漏的\documentclass
,改进了边缘标签定位