8

I had to draw rooted (upward oriented) trees (with leaves). I found the package forest useful, although most likely the work-arounds I employed are not really optimal in any proper sense. An example of such a tree may be the following.

\documentclass[a4paper,10pt]{article}
\usepackage[latin1]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{forest}
%opening
\title{}
\author{}
\date{}

\begin{document}
\begin{center}
 \begin{forest}
for tree={grow'=north, circle, draw, minimum width=0.7cm,anchor=center,fit=rectangle,
    edge={>=stealth,-,shorten >=1pt,shorten <=1pt,line width=0.5pt},
    scale=0.75,font=\sffamily\small\bfseries}
    %
 [, node options'
  [$l$, edge label={node[midway,right,font=\scriptsize]{a}}
    [$l'$, edge label={node[midway,left,font=\scriptsize]{b}}
      [, node options', edge label={node[midway,left,font=\scriptsize]{e}}]
      [, node options', no edge
    ]
      [, node options', edge label={node[midway,right,font=\scriptsize]{f}}]
    ]
    [, node options', no edge
    ]
    [, node options', edge label={node[midway,left,font=\scriptsize]{c}}
    ]
    [, node options', no edge
    ]
    [$l''$, edge label={node[midway,right,font=\scriptsize]{d}}
    ]
  ]
 ]
\end{forest}\end{center}
\end{document}

Question. How can I draw an arrow from one rooted tree to another one, as it is done (using xypic) at page 7 of this paper [1]?

[1] http://arxiv.org/pdf/math/0701293v2.pdf

4

Another option, allowing perhaps finer control over the arrows in case cfr's solution is not directly usable, would be to place the trees in TikZ's \nodes and then to use the nodes' names to draw the arrows.

The safer way to do this would be to first box the trees and then use the boxes inside a tikzpicture; in the following example I used the same tree three times, but this same idea can be applied for different trees using a different box for each one of the trees.

enter image description here

The code:

\documentclass[a4paper,10pt]{article}
\usepackage[latin1]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{forest}
\usetikzlibrary{positioning}

\newsavebox\boxa% we define a new box

% we fill the box
\savebox\boxa{%
\begin{forest}
for tree={grow'=north, circle, draw, minimum width=0.7cm,anchor=center,fit=rectangle,
    edge={>=stealth,-,shorten >=1pt,shorten <=1pt,line width=0.5pt},
    scale=0.75,font=\sffamily\small\bfseries}
    %
 [, node options'
  [$l$, edge label={node[midway,right,font=\scriptsize]{a}}
    [$l'$, edge label={node[midway,left,font=\scriptsize]{b}}
      [, node options', edge label={node[midway,left,font=\scriptsize]{e}}]
      [, node options', no edge
    ]
      [, node options', edge label={node[midway,right,font=\scriptsize]{f}}]
    ]
    [, node options', no edge
    ]
    [, node options', edge label={node[midway,left,font=\scriptsize]{c}}
    ]
    [, node options', no edge
    ]
    [$l''$, edge label={node[midway,right,font=\scriptsize]{d}}
    ]
  ]
 ]
\end{forest}%
}

\begin{document}

\begin{center}
\begin{tikzpicture}[node distance=0.5cm and 0.5cm]
\node[inner sep=0pt] (uc)
  {\usebox\boxa};
\node[inner sep=0pt,below left=of uc] (ll)
  {\usebox\boxa};
\node[inner sep=0pt,below right=of uc] (lr)
  {\usebox\boxa};
\begin{scope}[shorten >=10pt,shorten <=10pt]
\draw[->]
  (ll.north) -- node[auto] {$\partial_{v}$} (uc);  
\draw[->]
  (lr.north) -- node[swap,auto] {$\partial_{w}$} (uc);  
\end{scope}
\end{tikzpicture}
\end{center}

\end{document}
  • 1
    (+1) Is there a straightforward way of imposing a consistent style on edge labels? (Other than rewriting the edge path, which can have unwanted side effects.) I'm not sure whether this is a generic TiKZ question. – cfr Dec 13 '14 at 3:03
  • Amazing! I was hoping for something like that. Many thanks! – Andrea Gagna Dec 13 '14 at 12:00
4

One way is to draw the trees as a single tree with a phantom root node:

\documentclass[tikz,border=5pt]{standalone}
\usepackage[utf8]{inputenc}% just for this example as my editor uses this encoding
\usepackage[T1]{fontenc}
\usepackage{forest}

\begin{document}
\begin{forest}
for tree={grow'=north, circle, draw, minimum width=0.7cm,anchor=center,fit=rectangle,
    edge={>=stealth,-,shorten >=1pt,shorten <=1pt,line width=0.5pt},
    scale=0.75,font=\sffamily\small\bfseries}
    %
[,phantom, l sep=0pt, s sep+=20pt
  [, node options'
    [$l$, edge label={node[midway,right,font=\scriptsize]{a}}
      [$l'$, edge label={node[midway,left,font=\scriptsize]{b}}
        [, node options', edge label={node[midway,left,font=\scriptsize]{e}}]
        [, node options', no edge
      ]
        [, node options', edge label={node[midway,right,font=\scriptsize]{f}}]
      ]
      [, node options', no edge
      ]
      [, node options', edge label={node[midway,left,font=\scriptsize]{c}}
      ]
      [, node options', no edge
      ]
      [$l''$, edge label={node[midway,right,font=\scriptsize]{d}}, name=node1
      ]
    ]
  ]
  [, node options'
    [$l$, edge label={node[midway,right,font=\scriptsize]{a}}
      [$l'$, edge label={node[midway,left,font=\scriptsize]{b}}, name=node2
        [, node options', edge label={node[midway,left,font=\scriptsize]{e}}]
        [, node options', no edge
      ]
        [, node options', edge label={node[midway,right,font=\scriptsize]{f}}]
      ]
      [, node options', no edge
      ]
      [, node options', edge label={node[midway,left,font=\scriptsize]{c}}
      ]
      [, node options', no edge
      ]
      [$l''$, edge label={node[midway,right,font=\scriptsize]{d}}
      ]
    ]
  ]
]
  \draw [->, >=stealth, shorten >=10pt, shorten <=10pt, thick] (node1.east) -- (node2.west);
\end{forest}
\end{document}

phantom root

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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