循環樹中距邊的級別距離

循環樹中距邊的級別距離
\documentclass[png,tikz,border=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{trees,decorations,shadows}

% style definitions
\tikzset{level 1/.style={sibling angle=90,level distance=25mm}}

\begin{document}

\begin{tikzpicture}
[grow cyclic,cap=round]
\node[shape=circle, draw, minimum size=12pt] {\large PL} 
 child {node[shape=circle, draw, minimum size=8pt] {}
    [level distance=1cm]
    child {node {Textual}}
    child {node {Visual}}
}
 child {node[shape=circle, draw, minimum size=8pt] {}
    [level distance=1cm]
    child {node {General-purpose}}
    child {node {Special-purpose}}
}
 child {node[shape=circle, draw, minimum size=8pt] {}}
 child {node[shape=circle, draw, minimum size=8pt] {}}
;
\end{tikzpicture}

\end{document}

在此輸入影像描述

正如你所看到的,儘管我指定了level distance=1cm.它從中心開始測量,因此“特殊用途”離其父級太近。 「Textual」和「Visual」的邊長也不同。

我可以測量距邊緣的水平距離,以便無論文字長度如何,邊緣長度均為 1 公分嗎?

這個問題類似於在tikz中設定邊界之間的節點距離但那個帖子並不是在造樹。

答案1

另一種方法是使用chains,它預設測量節點邊界之間的距離。scopes當您有很多分支時,該庫會使程式碼更清晰。

在此輸入影像描述

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{chains, scopes}

\begin{document}

\begin{tikzpicture}[start chain, every on chain/.style=join, node distance=10mm and 10mm]
\node [on chain, draw, circle] {PL};
{[start branch=1 going above right]
    \node [on chain, draw, circle] {};
}
{[start branch=2 going above left]
    \node [on chain, draw, circle] {};
}
{[start branch=3 going below left]
    \node [on chain, draw, circle] {};
    {[start branch=31 going left]
    \node [on chain] {Textual};
    }
    {[start branch=32 going below]
    \node [on chain] {Visual};
    }
}
{[start branch=4 going below right]
    \node [on chain, draw, circle] {};
    {[start branch=41 going right]
    \node [on chain] {Special purpose};
    }
    {[start branch=42 going below]
    \node [on chain] {General purpose};
    }
}
\end{tikzpicture}

\end{document}

答案2

這是因為用於定位節點的座標位於每個節點的中心。您可以使用以下命令更改它anchor

\documentclass[border=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{trees}

% style definitions
\tikzset{level 1/.style={sibling angle=90,level distance=25mm}}

\begin{document}

\begin{tikzpicture}[grow cyclic,cap=round]
\node[shape=circle, draw, minimum size=12pt] {\large PL} 
 child {node[shape=circle, draw, minimum size=8pt] {}
    [level distance=1cm]
    child {node[anchor=east] {Textual}}
    child {node[anchor=north] {Visual}}
}
 child {node[shape=circle, draw, minimum size=8pt] {}
    [level distance=1cm]
    child {node[anchor=north] {General-purpose}}
    child {node[anchor=west] {Special-purpose}}
}
 child {node[shape=circle, draw, minimum size=8pt] {}}
 child {node[shape=circle, draw, minimum size=8pt] {}}
;
\end{tikzpicture}

\end{document}

在此輸入影像描述

相關內容