dot2tex & tikz:對齊簇

dot2tex & tikz:對齊簇

我的程式碼產生以下圖表:

\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}

在此輸入影像描述

相關內容