tikz-qtree 具有范围?(如何绘制凯莱公式)

tikz-qtree 具有范围?(如何绘制凯莱公式)

我想为凯莱公式制作一棵树,如下所示:

在此处输入图片描述

(但采用垂直布局)

我可以使用tikz-qtree下面第 1 部分所示的环境

我可以绘制第 2 节所示的图表

但如果我尝试将图形作为树的一个节点... 大错误! Nodeway 我使用范围将子图放在另一个中! 但没有成功。

我无法在此论坛或通过 Google 朋友找到答案。

以下是一个例子:

\documentclass{article}
\usepackage[a4paper]

\usepackage[ansinew]{inputenc}
\usepackage[french]{babel}
\usepackage{lmodern}
\usepackage[T1]{fontenc}
\usepackage{microtype}

\usepackage{color,xcolor}
\usepackage{etex} % pour supprimer l'erreur 'No rom for new dim' avec tikz (avant Titz)
\usepackage{tikz}
\usepackage{tikz-qtree}
\usetikzlibrary{scopes}

\begin{document}

\tikzset{%                      
    ptn/.style={% node point for caeyley
                    circle, 
                    inner sep=0.7pt,
                    fill=black,
                    draw
                    },
    pthb/.style={% path black for caeyley
                    thin, draw=darkgray},   
    pthr/.style={% path red for caeyley
                    thick, draw=red},                                   
    }

\section{Tree only}


      \begin{tikzpicture}
      \tikzset{execute at begin node=\strut}
      \tikzset{level distance=40pt}   
      \tikzset{frontier/.style ={distance from root=120pt}}
      \tikzset{edge from parent/.append style= %
      {draw,edge from parent path={(\tikzparentnode.south) -- +(0,-8pt) -| (\tikzchildnode)}}
      }   
      \Tree 
      [.Root 
        [.A 
            [.AA BB CC ] C  
            ] 
        [.B BB  
        ] 
      ]
    \end{tikzpicture}  


\section{Graph only}

        \begin{tikzpicture}%
        [x=5mm, y=5mm, semithick,every loop/.style={max distance = 2mm,looseness=60}]
        \node[ptn] (a) at (0,0) {};
        \node[ptn] (b) at (0,1) {};
        \node[ptn] (c) at (1,0) {};
        \node[ptn] (d) at (1,1) {};                               
        \path[pthb] 
        (a) edge (b) edge (c) 
        (d) edge (b) edge (c);
        \path[pthr] (a) edge (d);
    \end{tikzpicture}

\section{Graph in the tree ?}   

      \begin{tikzpicture}
      \tikzset{execute at begin node=\strut}
      \tikzset{level distance=40pt}   
      \tikzset{frontier/.style ={distance from root=120pt}} 
      \tikzset{edge from parent/.append style= % 
      {draw,edge from parent path={(\tikzparentnode.south) -- +(0,-8pt) -| (\tikzchildnode)}}
      \tikzset{every loop/.style={max distance = 2mm,looseness=60}}
      }   
      \Tree 
      [.\begin{scope}%[x=3mm,y=3mm,semithick]
        \node[ptn] (a) at (0,0) {};
        \node[ptn] (b) at (0,1) {};
        \node[ptn] (c) at (1,0) {};
        \node[ptn] (d) at (1,1) {};                               
        \path[pthb] 
        (a) edge (b) edge (c) edge (d)
        (d) edge (b) edge (c);
      \end{scope}   
        [.A 
            [.AA BB CC ] C  
            ] 
        [.B BB  
        ] 
      ]
    \end{tikzpicture} 

\end{document}

我该如何解决这个问题?

答案1

您所写的内容\begin{scope}已经位于节点内。此处 TikZ 宏已停用。您将需要tikzpicture它周围的环境。

不过,我会采用另一种方法,使用带有的简单节点append after command。这个想法来自我的答案TikZ 中的交换图中的图形

\matrix另一种方法是在节点的位置使用(这只是类型的节点matrix),可以在其中放置任意 TikZ 代码。

forest在这里使用,但如果您可以轻松访问节点,则tikz-qtree相同的方法应该适用。


据报道,下面显示的代码不适用于 TikZ 的官方 2.10 版本。可以通过将命令替换\tikzset{aac/.style=…

\forestset{append after command/.style={tikz={%
  \path[late options={name=\forestoption{name},append after command={#1}}];}},
  aac/.style={
    append after command={[shift=(\tikzlastnode.center),
      x={($(\tikzlastnode.east)-(\tikzlastnode.center)$)},
      y={($(\tikzlastnode.north)-(\tikzlastnode.center)$)}, #1]}}}

创造append after commandaac一种/forest风格。


shift需要注意的是,如果使用 PGF 宏,用、x和键给出的选项y也可以不用calc符号来表示,即:

\pgfextra{\pgftransformshift{\pgfpointanchor{\tikzlastnode}{center}}%
  \pgfsetxvec{\pgfpointdiff{\pgfpointanchor{\tikzlastnode}{center}}
             {\pgfpointanchor{\tikzlastnode}{east}}}%
  \pgfsetyvec{\pgfpointdiff{\pgfpointanchor{\tikzlastnode}{center}}
             {\pgfpointanchor{\tikzlastnode}{north}}}}

代码

\documentclass[tikz]{standalone}
\usepackage{forest}
\tikzset{aac/.style={
    append after command={[shift=(\tikzlastnode.center),% every edge/.append style={opacity=.5},
      x={($(\tikzlastnode.east)-(\tikzlastnode.center)$)},
      y={($(\tikzlastnode.north)-(\tikzlastnode.center)$)}, #1]}}}
\tikzset{
  dot/.style={shape=circle,fill,draw,inner sep=+0pt, minimum size=+2pt},
  % squares
  square/.style={insert path={\foreach \a[count=\c] in {45,135,225,315}{(\a:.7) node[dot] (s-\c) {}}}},
  square U/.style={square,insert path={(s-3) edge (s-4) edge (s-2) (s-4) edge (s-1)}},
  square O/.style={square U, insert path={(s-1) edge (s-2)}},
  square Oslash/.style={square O, insert path={(s-2) edge (s-4)}},
  % triangles (the yshift is not good)
  triangle/.style={yshift=+1.5pt, insert path={\foreach \a[count=\c] in {30, 150, 270} {(\a:.7) node[dot] (t-\c) {}}}},
  triangle V/.style={triangle, insert path={(t-3) edge (t-1) edge (t-2)}},
  triangle full/.style={triangle V, insert path={(t-1) edge (t-2)}},
  % ring2
  ring2/.style={insert path={edge[to path={circle [radius=.5]}]() (up:.5) coordinate[dot] (r2-1) (down:.5) coordinate[dot] (r2-2)}},
  % ring3
  ring3/.style={insert path={(0,0) coordinate (r3-1) (left:.7) coordinate (r3-2) (right:.7) coordinate (r3-3)}},
  ring3 o.o/.style={ring3, insert path={
    (r3-1) edge[to path={arc[radius=.35, start angle=0,   delta angle=360]}] ()
           edge[to path={arc[radius=.35, start angle=180, delta angle=360]}] ()
           node[dot]{}}},
  ring3 .o.o/.style={ring3 o.o, insert path={(r3-2) node[dot]{}}},
  ring3 .o.o./.style={ring3 .o.o, insert path={(r3-3) node[dot]{}}},
  ring3 o.-./.style={ring3, insert path={
    (r3-1) coordinate[dot] (@) edge[to path={arc[radius=.35, start angle=0, delta angle=360]}] ()
                       (r3-3) node[dot] {} edge (@)}},
  ring3 .o.-./.style={ring3 o.-., insert path={(r3-2) node[dot]{}}},
  % misc
  just a line/.style={insert path={(left:.75) coordinate[dot] (@) (right:.75) node[at end, dot]{} edge (@)}}
}
\begin{document}
\begin{forest} for tree={node options={minimum size=+15pt}},
[,aac=square Oslash
  [,aac=ring3 .o.o.
    [,aac=ring3 .o.o
      [,aac=ring3 o.-.]
      [,aac=ring3 o.o]
    ]
    [,aac=ring3 .o.-.
      [,rotate=-90, aac={ring3 o.-.}]
      [,aac=triangle V]
    ]
  ]
  [,aac=square O
    [,aac=square U]
    [,aac=triangle full
      [,aac=ring2
        [,aac=ring3 o.o]
        [,aac=just a line]
      ]
      [,aac=triangle V]
    ]
  ]
]
\end{forest}

输出

在此处输入图片描述

相关内容