
\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}
Como você pode ver, embora eu especifique level distance=1cm
. Ele mede a partir do centro, portanto, "Propósito especial" está muito próximo de seu pai. Os comprimentos das bordas de "Textual" e "Visual" também são diferentes.
Posso medir a distância nivelada das bordas de modo que o comprimento da borda seja de 1 cm, independentemente do comprimento do texto?
Este problema é de certa forma semelhante aoDefinir a distância do nó entre as bordas no tikzmas esse posto não está construindo árvores.
Responder1
Uma alternativa é usar chains
, que por padrão mede a distância entre as bordas dos nós. A scopes
biblioteca torna o código mais limpo quando você tem muitas ramificações.
\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}
Responder2
Isso ocorre porque o coordenado usado para posicionar os nós fica no centro de cada nó. Você pode mudar isso usando 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}