我的代码生成以下图表:
\documentclass{standalone}
\usepackage{tikz}
\usepackage{dot2texi}
\begin{document}
\begin{tikzpicture}[auto]
\tikzstyle{n} = [draw,shape=rectangle,minimum size=2em,inner sep=2pt,align=center, font=\sffamily]
\begin{dot2tex}[dot,tikz,codeonly,styleonly, options= -s ]
digraph G {
overlap = false;
node [style="n"];
root
top1
top2
subgraph cluster_top3 {
top3 ;
color=invis;
top3 -> {311 312} -> 32 -> {331 332 333} -> 34 -> 35 -> 36;
}
subgraph cluster_top4 {
color=invis;
top4 -> 41 -> {421 422} -> 43 -> 44 -> 45;
}
root -> {top1 top2 top3 top4};
}
\end{dot2tex}
\end{tikzpicture}
\end{document}
有没有办法生成对称子图,而无需摆弄不可见的节点/边?我想要三角形311 -- top3 -- 312
并421 -- 41 -- 422
有一个直角。
答案1
在仔细研究了 pgf 手册后,我想出了这个解决方案。但是子树的级别没有对齐。
\RequirePackage{luatex85}
\documentclass\[tikz,12pt,border=0pt\]{standalone}
\usepackage{tikz}
\usetikzlibrary{graphdrawing}
\usetikzlibrary{graphs}
\usegdlibrary{trees}
\usegdlibrary{layered}
\usetikzlibrary{shapes}
\begin{document}
\begin{tikzpicture}\[>=stealth, -, line width=2pt, every node/.style={circle, font=\Large, draw=black, minimum size=1.45cm, fill=white, anchor=center, align=center, line width=2pt}\]
\graph \[tree layout, level distance=2cm, sibling distance=2cm, components go up center aligned=true\]
{
"top" -- {1, 2, 3, 4};
// \[layered layout, level distance=2cm, sibling distance=2cm\]{{311, 312} -- 32 -- {331, 332, 333} -- 34};
3 -- {311, 312};
// \[layered layout, level distance=2cm, sibling distance=2cm\] {41 -- {421, 422} -- 43;};
4 -- 41;
};
\end{tikzpicture}
\end{document}