答案1
您可以使用grow
pgfmanual 第 218 页中描述的密钥:
此键用于定义树的生长方向。方向可以是角度(以度为单位),也可以是以下特殊文本字符串之一:、 、 、 、 、 、 、 、 、 和
down
。up
所有left
这些right
都有north
“south
其east
明显west
的north east
含义north west
” ,因此,可以说,与角度 相同。south east
south west
south west
-135◦
对于您来说,您可以使用grow=up
;一个小例子:
\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
[level distance=10mm,
every node/.style={fill=red!60,circle,inner sep=1pt},
level 1/.style={sibling distance=20mm,nodes={fill=red!45}},
level 2/.style={sibling distance=10mm,nodes={fill=red!30}},
level 3/.style={sibling distance=5mm,nodes={fill=red!25}}]
\node {31} [grow=up]
child {node {30}
child {node {20}
child {node {5}}
child {node {4}}
}
child {node {10}
child {node {9}}
child {node {1}}
}
}
child {node {20}
child {node {19}
child {node {1}}
child[missing]
}
child {node {18}}
};
\end{tikzpicture}
\end{document}
根据节点的所需顺序,您可以改用grow'
:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{shapes}
\begin{document}
\begin{tikzpicture}
[level distance=10mm,
every node/.style={fill=red!60,circle,inner sep=1pt},
level 1/.style={sibling distance=20mm,nodes={fill=red!45}},
level 2/.style={sibling distance=10mm,nodes={fill=red!30}},
level 3/.style={sibling distance=5mm,nodes={fill=red!25}}]
\node {31} [grow'=up]
child {node {30}
child {node {20}
child {node {5}}
child {node {4}}
}
child {node {10}
child {node {9}}
child {node {1}}
}
}
child {node {20}
child {node {19}
child {node {1}}
child[missing]
}
child {node {18}}
};
\end{tikzpicture}
\end{document}