tikz 树 - 子节点附加到错误的节点

tikz 树 - 子节点附加到错误的节点

考虑

\usetikzlibrary{calc,decorations.pathreplacing,shapes.symbols}
\begin{tikzpicture}
\node [shape=cloud,aspect=2,draw] {\strut}
  [level distance=6em,sibling distance=1.5em,grow=45]
  child {node[shape=circle,draw] (B) {}} 
  child {node[shape=circle] {}}
  child {node[shape=circle] {}}
  child {node[shape=circle] {}}
  child {node[shape=circle,draw] (A) {}}
  [grow=-45]
  child child child child 
;
\draw [line width=1.5mm,line cap=round,
             dash pattern={on 0pt off 3mm},dash phase=1.25mm]
    (A.south east) -- (B.north west) ;
\draw [decorate,decoration={brace,amplitude=2mm}]
($(A.north east)+(.5mm,.5mm)$) --
($(B.north east)+(.5mm,.5mm)$)
;
\node [anchor=south west] at ($(A.north east)!.5!(B.north east)+(2mm,2mm)$)
    {Cluster 1} ;
\end{tikzpicture}

目的是让云形节点拥有两个子节点集群,一个在右上方,另一个在右下方。实际发生的情况是,选项之后的所有子节点[grow=-45]都附加到其上方的子节点,尽管没有嵌套到该子节点中。
在此处输入图片描述

发生了什么?我该如何解决这个问题?

(此外,如果能提出一些不那么繁琐的方法来定位花括号、虚线和“Cluster 1”标签,我们将不胜感激)

编辑:如果这是一个已知的错误:

Package: pgfrcs 2010/10/25 v2.10 (rcs-revision 1.24)
Package: pgf 2008/01/15 v2.10 (rcs-revision 1.12)
Package: pgfsys 2010/06/30 v2.10 (rcs-revision 1.37)
Package: pgfcore 2010/04/11 v2.10 (rcs-revision 1.7)
Package: pgfcomp-version-0-65 2007/07/03 v2.10 (rcs-revision 1.7)
Package: pgfcomp-version-1-18 2007/07/23 v2.10 (rcs-revision 1.1)
Package: pgffor 2010/03/23 v2.10 (rcs-revision 1.18)
Package: tikz 2010/10/13 v2.10 (rcs-revision 1.76)

... 那些看起来有点旧了,嗯。

答案1

一个建议是为每个集群创建一个虚拟级别child。另一种方法是使用child[missing]。但是,也许最接近原始图片的是为每个子集合绘制一棵单独的树,并将填充白色的云放在顶部作为最后的东西。以下是最后一种可能性的代码,然后是第一种可能性的代码:

带顶部节点覆盖的样本

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{calc,decorations.pathreplacing,shapes.symbols}
\begin{document}
\begin{tikzpicture}
\node {}
  [level distance=6em,sibling distance=1.5em,grow=-45]
  child {node[shape=circle,draw] (B) {}} 
  child {node[shape=circle] {}}
  child {node[shape=circle] {}}
  child {node[shape=circle] {}}
  child {node[shape=circle,draw] (A) {}};
\node {} [level distance=6em,sibling distance=1.5em,grow=45]
  child {node[shape=circle,draw] (C) {}} 
  child {node[shape=circle] {}}
  child {node[shape=circle] {}}
  child {node[shape=circle] {}}
  child {node[shape=circle,draw] (D) {}} ;
\node [shape=cloud,aspect=2,draw,fill=white] {\strut};

\draw [line width=1.5mm,line cap=round,
             dash pattern={on 0pt off 3mm},dash phase=1.5mm]
    (A.south west) -- (B.north east) ;
\draw [decorate,decoration={brace,amplitude=2mm}]
($(A.east)+(1mm,0mm)$) -- ($(B.east)+(-2mm,-3mm)$) ;
\node [anchor=south west] at ($(A.east)!.5!(B.east)+(1mm,-6mm)$)
    {Cluster 1} ;
\draw [line width=1.5mm,line cap=round,
             dash pattern={on 0pt off 3mm},dash phase=1.5mm]
    (D.south east) -- (C.north west) ;
\draw [decorate,decoration={brace,amplitude=2mm}]
($(D.east)+(-2mm,3mm)$) -- ($(C.east)+(1mm,0mm)$) ;
\node [anchor=south west] at ($(D.east)!.5!(C.east)+(1mm,1mm)$)
    {Cluster 2} ;
\end{tikzpicture}

\end{document}

示例输出

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{calc,decorations.pathreplacing,shapes.symbols}
\begin{document}
\begin{tikzpicture}
\node [shape=cloud,aspect=2,draw] {\strut}
  [level distance=2em,sibling distance=2em,grow=0]
  child{
  [level distance=6em,sibling distance=1.5em,grow=-45]
  child {node[shape=circle,draw] (B) {}} 
  child {node[shape=circle] {}}
  child {node[shape=circle] {}}
  child {node[shape=circle] {}}
  child {node[shape=circle,draw] (A) {}} }
 child{  [level distance=6em,sibling distance=1.5em,grow=45]
  child {node[shape=circle,draw] (C) {}} 
  child {node[shape=circle] {}}
  child {node[shape=circle] {}}
  child {node[shape=circle] {}}
  child {node[shape=circle,draw] (D) {}} }
;
\draw [line width=1.5mm,line cap=round,
             dash pattern={on 0pt off 3mm},dash phase=1.5mm]
    (A.south west) -- (B.north east) ;
\draw [decorate,decoration={brace,amplitude=2mm}]
($(A.east)+(1mm,0mm)$) -- ($(B.east)+(-2mm,-3mm)$) ;
\node [anchor=south west] at ($(A.east)!.5!(B.east)+(1mm,-6mm)$)
    {Cluster 1} ;
\draw [line width=1.5mm,line cap=round,
             dash pattern={on 0pt off 3mm},dash phase=1.5mm]
    (D.south east) -- (C.north west) ;
\draw [decorate,decoration={brace,amplitude=2mm}]
($(D.east)+(-2mm,3mm)$) -- ($(C.east)+(1mm,0mm)$) ;
\node [anchor=south west] at ($(D.east)!.5!(C.east)+(1mm,1mm)$)
    {Cluster 2} ;
\end{tikzpicture}

\end{document}

[grow=-45]正如您所发现的,不允许进行诸如您的样式更改;样式可以放置在根节点之后child或之后nodes,也可以放置在根节点之后。请参阅第 18.4 节“指定树和子节点的选项”中的图表pgfmanual

相关内容