Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I want to make a tree for the Cayley formula as this :

enter image description here

(But with a vertical layout)

I can use the tikz-qtree environments as show in section 1 below

I can draw the graph as show in section 2

But if I try to put a graph as a node of the tree ... big bug ! Nodeway i use the scope tp put the sub-fig in the other ! But without success.

I can't find a anwser in this forum or with the Google-friend.

Here's a exemple :

\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}

How can I solve this ?

share|improve this question
    
You code doesn't compile; please correct it. –  Gonzalo Medina Nov 25 '12 at 23:13
    
I know it doen't work, it's my question ;-) If you comment the tikz in section 3 you can compile the section 1 and 2, but the problem is precisely to make the graph at section 3 ... where it bug. –  madit Nov 26 '12 at 6:14

1 Answer 1

up vote 2 down vote accepted

Where you write \begin{scope} you are already inside a node. Here TikZ macros are deactivated. You will need the tikzpicture environment around it.

Though, I would go another approach and use simple nodes with append after command. The idea is taken from my answer to Graphs in commutative diagrams in TikZ.

Another approach would be to use a \matrix at the place of a node (which is just a node from the type matrix) where on can place arbitrary TikZ code in it.

I use forest here but if you can easily access the nodes in tikz-qtree the same approach should be applicable.


It has been reported that the code shown below does not work with TikZ’s official 2.10 version. This can be solved by replacing the \tikzset{aac/.style=… command with

\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]}}}

making both append after command and aac a /forest style.


It should be noted that the options given with the shift, the x and the y key can also be expressed without calc’s notation if PGF macros are used, i.e.:

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

Code

\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}

Output

enter image description here

share|improve this answer
    
Thank you ! I've recently discover this package 'forest' too –  madit Nov 14 '13 at 20:07
    
If I try your code i get 101 errors. Most of them are "Pgf Error: No shape named ... is known" –  madit Nov 14 '13 at 20:20
    
@madit I don’t get any errors with the CVS version of TikZ but with the stable version. Looks like somehow \tikzlastnode from append after command is accessed too early (before the node actually exists or is drawn) and that throws everything off. (See forest’s label option for more discussion on this.) I don’t know how to solve this with forest options … –  Qrrbrbirlbel Nov 14 '13 at 21:02
    
@madit See my updated answer. –  Qrrbrbirlbel Nov 14 '13 at 23:38
    
Ok I see the comments. And it works now with replacing in your code the first tikzset by forestset (and adding an \end{document}. Thank you !!! –  madit Nov 16 '13 at 15:28

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.