我想将“2222”节点与同一级别的其他节点左对齐(参见下面的 MWE)。使用 TikZ 3.0 的绘图库可以实现这一点吗?到目前为止我还没能解决这个问题。
\documentclass[tikz,border=10pt]{standalone}
\usetikzlibrary{graphdrawing}
\usetikzlibrary{graphs}
\usegdlibrary{trees}
\begin{document}
\begin{tikzpicture}[>=stealth,every node={align=left}]
\graph [tree layout, grow'=right, fresh nodes, level distance=0.5in,
sibling distance=0.1in]
{
4 -> {
3 -> { 1 -> { 5, " " }, 2,2 },
3 -> { 1, 2, 2 },
3 -> { 1, 2, 2222 }
}
};
\end{tikzpicture}
\end{document}
答案1
相反,every node={align=left}
在tikzpicture
参数中你应该说:
every node/.style={anchor=west}
结果:
升级:对我来说,对于编辑过的问题,以下解决方案看起来更好:
\documentclass[tikz,border=10pt]{standalone}
\usetikzlibrary{graphdrawing, graphs}
\usegdlibrary{trees}
\begin{document}
\begin{tikzpicture}[>=stealth,
every node/.style={anchor=west}] % <---
\graph [tree layout, grow'=right,
fresh nodes, level distance=0.5in,
sibling distance=0.1in
]
{
4 -> {
3 -> { 1 -> { 5, " " }, 2,2 },
3 -> { 1, 2, 2 },
3 -> [head anchor=west]{ 1, 2, 2222} % head anchor=west can be
% mowed to graph preamble
}
};
\end{tikzpicture}
\end{document}
它给:
注意:MWE需要由LuaLaTeX编译。
答案2
感谢 Zarko,我得到了一个可行的解决方案:
\documentclass[tikz,border=10pt]{standalone}
\usetikzlibrary{graphdrawing}
\usetikzlibrary{graphs}
\usegdlibrary{trees}
\begin{document}
\begin{tikzpicture}[>=stealth,every node/.style={anchor=west}]
\graph [tree layout, grow'=right, fresh nodes, level distance=3cm,
sibling distance=2ex, head anchor=west]
{
4 -> {
3 -> { 1 -> { 5, " " }, 2,2 },
3 -> { 1, 2, 2 },
3 -> { 1, 2, 2222 }
}
};
\end{tikzpicture}
\end{document}
给出