我正在尝试使用 Tikz 的 child 函数创建具有多个级别的层次结构图。但是,由于框的大小不同(即使在人为调整行数后),它看起来很糟糕。有人知道如何修复矩形的大小吗?
平均能量损失
\documentclass[11pt]{beamer}
\usepackage{tikz}
\usetikzlibrary{patterns}
\usetikzlibrary{decorations.pathreplacing,calligraphy}
\usetikzlibrary{calc}
\begin{document}
\begin{frame}{MWE}
\begin{figure}
\begin{tikzpicture}[sibling distance=6em,level distance=5em,every node/.style={shape=rectangle,draw,align=center}]
%\begin{tikzpicture}[
%every node/.style={shape=rectangle,draw,align=center}]
\node{\footnotesize Some title at the top \\ \footnotesize (ALMP)}
child{node{\footnotesize ahsfafasd \\ \footnotesize aasfasf}}
child{node{\footnotesize Trasfas \\ \footnotesize asfasms}}
child{node{\footnotesize afst \\ \footnotesize incasfasves}
child{node{\footnotesize asfasf \\ \footnotesize supplements}}
child{node{\footnotesize Hfass \\ \footnotesize fasfas}}
child{node{\footnotesize sfasdf \\ \footnotesize fasfas}}}
child{node{\footnotesize efaecfasd \\ \footnotesize joasfas}};
\end{tikzpicture}
\end{figure}
\end{frame}
\end{document}
输出
答案1
像这样:
\documentclass[11pt]{beamer}
\usepackage{tikz}
\begin{document}
\begin{frame}{MWE}
\begin{figure}
\begin{tikzpicture}[
sibling distance=6em,
level distance=5em,
every node/.style={draw,
text width=5em, align=center,
minimum height=6ex,
execute at end node=\vphantom{p},
font=\footnotesize}
]
\node{Some title at the top (ALMP)}
child{node{ahsfafasd aasfasf}}
child{node{Trasfas asfasms}}
child{node{afst incasfasves}
child{node{asfasf supplements}}
child{node{Hfass fasfas}}
child{node{sfasdf fasfas}}
}
child{node{efaecfasd joasfas}};
\end{tikzpicture}
\end{figure}
\end{frame}
\end{document}
在这种情况下,如果您希望拥有更宽的根节点,那么可以这样写:
\node[text width=8em] {Some title at the top\\ (ALMP)}
编译结果如下:
附录:
使用该forest
包后,您的树的代码会更简单、更短:
\documentclass[11pt]{beamer}
\usepackage{forest}
\begin{document}
\begin{frame}{MWE}
\begin{figure}
\begin{forest}
for tree = {
% nodes
draw,
where level=0{text width=8em}{text width=5em},
text centered,
minimum height=6ex,
execute at end node=\vphantom{p},
font=\footnotesize,
% tree
anchor=north,
l sep=12mm,
s sep=2mm,
}
[Some title at the top\\ (ALMP)
[ahsfafasd aasfasf]
[Trasfas asfasms]
[afst incasfasves
[asfasf supplements]
[Hfass fasfas]
[sfasdf fasfas]
]
[efaecfasd joasfas]
]
\end{forest}
\end{figure}
\end{frame}
\end{document}