I am trying to generate a tree like: enter image description here

Here is my code so far:



\begin{tikzpicture}[every tree node/.style={font=\huge},
level distance=1.1cm,sibling distance=.8cm, 
edge from parent path={(\tikzparentnode.south) -- +(0,-8pt) -| (\tikzchildnode)}],
frontier/.style={distance from root=350pt} % Align leaf nodes

\edge node[near end,left] {branch};
\edge node[near end, left] {};
\edge node[] {}; [.a ]
\edge node[] {}; [.b ]        
\edge node[] {}; [.c ]
\edge node[near end,right] {};
\edge node[] {}; [.d ]
\edge node[] {}; [.e ]
\node[draw] at (0,.2) {root};
\draw (1.6,-1.9) circle (1.3cm);
\draw[thick,->] (0,-4.5) -- (1,-3.2);
\node[draw] at (0,-5) {clade};


Which produces the following (PDFLaTex):

enter image description here

My questions are:

  1. How to make all the leaves appear at the same level?
  2. Is there a better way of drawing circles than manually locating it on the tree?
  3. How to make the tree horizontal?

1 Answer 1


You can use the fit library to fit a node to a set of named nodes. If you use Forest to draw the tree, it offers the fit to=<nodewalk> wrapper to make this easy.

For example,

clades & things

  forked edges,
  /tikz/every pin edge/.append style={Latex-, shorten <=2.5pt, darkgray},
  /tikz/every pin/.append style={darkgray, font=\sffamily},
  /tikz/every label/.append style={darkgray, font=\sffamily},
  before typesetting nodes={
      where content={}{coordinate}{},
    where n children=0{tier=terminus, label/.process={Ow{content}{right:#1}}, content=}{},
  for tree={
    s sep'+=10pt,
    l sep'+=15pt,
  l sep'+=50pt,
    \node [draw=blue, circle, ellipse, densely dashed, fit to={1,tree}, pin={[pin distance=50pt,name=clades]-40:clades}] {};
    \node (p) [draw=blue, circle, ellipse, densely dashed, fit to={l,tree}] {};
    \draw [every pin edge] (p) -- (clades);
  [, !l.edge label={coordinate [pos=0, pin=-135:root] }, !1.edge label={node [pos=.65, every label, above] {branch}}, !11.edge label={coordinate [pos=0, pin={[pin distance=30pt, align=center]135:internal\\node}] }
        [tip (terminal node)]

  • Thanks!! I am getting errors Illegal parameter number in definition of \pgf@temp. ^^I\end{forest} and Package pgfkeys Error: I do not know the key '/forest/label/.process', to whiu misspelled it. ^^I\end{forest} which is for this piece of the code label/.process={Ow{content}{right:#1}},. Is it because of outdated packages?
    – havij
    May 23, 2017 at 17:09
  • @rzmn Probably. If you get that error when you try to compile exactly the code I posted in a clean .tex, then almost certainly you have an older version of Forest. .process is relatively new and has been extended. Which version of Forest do you have? I've got 2.1.4.
    – cfr
    May 23, 2017 at 17:15
  • yes, I am using the exact code in a clean .tex file. From the .log file it is 'forest 2016/03/04 v2.0.2'
    – havij
    May 23, 2017 at 17:22
  • @rzmn Yes. It is because you have an older version of the package. Is updating an option?
    – cfr
    May 23, 2017 at 17:25
  • 1
    @rzmn That depends on how you installed TeX ;). If you used TeX Live or MikTeX, you can just use the package manager. If you are using packages provided by your Linux distro, it can be less straightforward. (That is, you're using apt or something rather than TeX Live's upstream distribution.)
    – cfr
    May 23, 2017 at 17:36

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.