2

I would like to draw trees using xymatrix, however using for example

\xymatrix{\ar@{-}[dr] & & \ar@{-}[dl]\\ & \ar@{-}[d] & \\ & & }

returns the image

My problem with this is the fact that the edges don't join in the middle. Is there a way to correct to this (possibly not involving passing to tikz)?

  • Do you need to draw trees or graphs? There are a couple of linguistic tree drawing packages based on xypic but they really assume you are drawing single rooted n-ary trees with downward branches, typically with node labels. – Alan Munn Dec 5 '15 at 22:46
  • @AlanMunn I am drawing single rooted n-ary trees with upward branches, often with leaves labelled, and sometimes also some vertices. Do you know of any package that would suit my case? I tried looking around, but didn't find anything... – Daniel Robert-Nicoud Dec 5 '15 at 22:49
  • Why do you want to avoid TikZ particularly? But, there are ps- packages for drawing trees, which seem comparable to some of the TikZ packages. (Not forest, probably, but probably tikz-qtree etc.) At least, I believe so. – cfr Dec 5 '15 at 23:08
  • @cfr Well, I already more or less know how to do it in tikz, but it's usually a lot of work... I'm actually trying to write some macros to do this in tikz faster. – Daniel Robert-Nicoud Dec 5 '15 at 23:12
  • I would second @cfr 's suggestion. Drawing upwards trees with tikz-qtree or forest (both of which use tikz) is relatively trivial. It's only the standard tree methods in tikz that are slow to input. These packages use a bracketed notation which is very fast to input. – Alan Munn Dec 5 '15 at 23:15
2

There is a tree drawing package for linguistics based on xypic called xyling. It can do what you want, but since most linguistics trees assume node labels, and downward branches, drawing trees up will be a bit of hack. The main syntax uses xymatrix underlyingly, and implements some node commands and a \B command to make branches. The optional argument to the \B command is an adjustment to extend the node upwards to the empty node above.

\documentclass{article}

\usepackage{xyling}
\begin{document}
\Tree{ \B{dr} & & \B{dl} \\
        &\B[6]{d}\\
        &  &\\
}

\end{document}

output of code

1

Here's an example with forest. It is straightforward, once you have styles defined for the kinds of trees you need, to apply them. Trees can then be specified extremely concisely.

In this case, we define a style my tree and then apply it to a tree as follows:

\begin{forest}
  my tree
  [Aardvarks
    [Agglomeration
      [
        [
          [Aggrandisement]
          [Artificiality]
        ]
      ]
    ]
    [Anticipation
      [Ants]
      [Ant-Eaters, tikz={\draw [densely dashed, ->, red] (.parent anchor) [out=45, in=135] to (!s.parent anchor);}]
    ]
  ]
\end{forest}

To produce

red in tooth and claw

The longest part of this is the arrow showing the ant-eaters eating the ants. But if you often need to illustrate that nature is red in tooth and claw, you could easily set up a style for this and just say e.g.

      [Ant-Eaters, tooth and claw]

to achieve the same result. But this is probably not a standard feature of linguistic trees and unnecessary here.

\documentclass[tikz,border=10pt,multi]{standalone}
\usepackage{forest}
\forestset{
  my tree/.style={
    for tree={
      parent anchor=north,
      child anchor=south,
      grow=90,
    },
    nice empty nodes up
  },
  nice empty nodes up/.style={% modified from page 52
    for tree={calign=fixed edge angles},
    delay={where content={}{shape=coordinate,for parent={for children={anchor=south}}}{}}
  }
}
\begin{document}
\begin{forest}
  my tree
  [Aardvarks
    [Agglomeration
      [
        [
          [Aggrandisement]
          [Artificiality]
        ]
      ]
    ]
    [Anticipation
      [Ants]
      [Ant-Eaters, tikz={\draw [densely dashed, ->, red] (.parent anchor) [out=45, in=135] to (!s.parent anchor);}]
    ]
  ]
\end{forest}
\end{document}

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.