순환 트리의 가장자리로부터 레벨 거리

순환 트리의 가장자리로부터 레벨 거리
\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"의 가장자리 길이도 다릅니다.

텍스트 길이와 상관없이 모서리 길이가 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}

여기에 이미지 설명을 입력하세요

관련 정보