防止 tikzpicture 重叠的简单解决方案是什么。我尝试更改同级距离和级别距离,但正如您在我的代码/图片中看到的那样,euqation2 不可见,因为它位于 equation1 下。
\documentclass[oneside, english, 12pt]{book}
\usepackage[a4paper]{geometry}
\usepackage[bitstream-charter]{mathdesign}
\usepackage{tikz}
\tikzset{
treenode/.style = {shape=rectangle, rounded corners,
draw, align=center,
top color=white, bottom color=blue!30!white},
root/.style = {treenode, font=\Large, bottom color=red!20!white},
env/.style = {treenode, font=\ttfamily\normalsize},
dummy/.style = {circle,draw}
}
\begin{document}
\begin{tikzpicture} [
grow = right,
sibling distance = 15em,
level distance = 10em,
edge from parent/.style = {draw, -latex},
every node/.style = {font=\footnotesize},
sloped ]
\node [root] {Formula}
child { node [dummy] {}
child { node [env] {equation1}
edge from parent node [below] {single-line?} }
child { node [env] {equation2}
edge from parent node [below] {multi-line?} }}
child { node [dummy] {}
child { node [env] {equation3}
edge from parent node [above] {at several}
node [below] {places?} }
child { node [env] {equation4}
edge from parent node [above] {centered?} } };
\end{tikzpicture}
\end{document}
答案1
例如,您可以添加:
level 1/.style={sibling distance = 15em},
level 2/.style={sibling distance = 10em},
在tikzpicture
选项中,这样就不会发生重叠。
答案2
如果您准备使用其他软件包,Forest 会自动处理树中节点的布局,尽管您需要稍微调整级别之间的距离以腾出空间放置标签。它的树语法也更加简洁,并且默认情况下会生成非常节省空间的树。
例如:
\documentclass[tikz,multi,border=10pt]{standalone}
\usepackage{forest}
\usepackage[bitstream-charter]{mathdesign}
\tikzset{%
treenode/.style = {shape=rectangle, rounded corners, draw, align=center, top color=white, bottom color=blue!30!white},
root/.style = {treenode, font=\Large, bottom color=red!20!white},
env/.style = {treenode, font=\ttfamily\normalsize},
dummy/.style = {circle, draw}
}
\begin{document}
\begin{forest}
over label/.style={%
edge label+={node [midway, above, anchor=south, sloped, font=\footnotesize] {#1}},
},
under label/.style={%
edge label+={node [midway, below, anchor=north, sloped, font=\footnotesize] {#1}},
},
for tree={
grow = east,
edge={-latex},
calign=fixed angles,
l sep=5em,
}
[Formula, root
[, dummy
[equation1, env, under label={single line?}
]
[equation2, env, under label={multi-line?}
]
]
[, dummy
[equation3, env, over label={at several}, under label=places
]
[equation4, env, over label={centred?}
]
]
]
\end{forest}
\end{document}