
\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
、中心から測定するため、「Special-purpose」は親に近すぎます。また、「Textual」と「Visual」のエッジの長さも異なります。
テキストの長さに関係なく、エッジの長さが 1cm になるように、エッジからのレベル距離を測定できますか?
この問題は、ある意味では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}