TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'd like to align all leaves of a tree at the bottom, so what I'd like to achieve should look like:

    p
   / \
  /  /\
 c  d  e

What I've tried so far (using tikz-qtree) results in:

    p
   / \
  c  /\
    d  e

I'm currently using tikz-qtree, but if there's an alternative better suited to the task, feel free to suggest one ;) Sidenote: I'm actually not labeling nodes, but edges.

Code:

\documentclass[12pt]{article}
\usepackage[active,pdftex,tightpage]{preview}
\usepackage{tikz-qtree}
\PreviewEnvironment[]{tikzpicture}
\begin{document}
\begin{tikzpicture}[every tree node/.style={draw,circle},sibling distance=10pt,
edge from parent path={(\tikzparentnode) -- (\tikzchildnode)}]
\tikzstyle{every node}=[font=\tiny, sloped,anchor=south,auto=false,inner sep=1pt]
\Tree
[.{}
    \edge node[]{C};
    [.{}
    ]
    \edge node[]{A};
    [.{}
        \edge node[]{D};
        [.{}
        ]
        \edge node[]{E};
        [.{}
        ]
    ]
]
\end{tikzpicture}
\end{document}
share|improve this question
1  
Welcome to TeX.SX! Please add a minimal working example (MWE) that illustrates your problem. It will be much easier for us to reproduce your situation and find out what the issue is when we see compilable code, starting with \documentclass{...} and ending with \end{document}. – Jubobs Jun 13 '13 at 9:44
    
Slightly related: qtree items do not have the same baseline – Claudio Fiandrino Jun 13 '13 at 11:52
2  
A related question: How to draw syntactical trees with parallel leafs for a natural language? Will this question solve your problem? – Alan Munn Jun 13 '13 at 12:12
up vote 1 down vote accepted

Here's a forest solution which allows the tree to be specified quite concisely. Once the preamble of the tree is configured (which could also be saved as a style, for example), we can write

  [
    [c]
    [a
      [d]
      [e]
    ]
  ]

to produce

auto-labelling

The alignment of the final nodes in the tree is accomplished with

    if n children=0{tier=terminal}{},

Complete code:

\documentclass[tikz,border=10pt,multi]{standalone}
\usepackage{forest}
\begin{document}
\begin{forest}
  for tree={
    draw,
    circle,
    delay={
      if level=0{}{
          edge label/.wrap pgfmath arg={node [font=\tiny, sloped, midway, anchor=south, auto=false, inner sep=1pt] {#1} }{content()}
      },
    },
    if n children=0{tier=terminal}{},
    s sep=10pt,
  },
  before typesetting nodes={
    for tree={
      content=,
    }
  }
  [
    [c]
    [a
      [d]
      [e]
    ]
  ]
\end{forest}
\end{document}
share|improve this answer

This code generates what you need:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{trees}

\begin{document}
    \begin{figure}
        \begin{center}
        \tikzstyle{level 1}=[level distance=1.5cm, sibling distance=2.5cm]
        \tikzstyle{level 2}=[level distance=1.5cm, sibling distance=2.5cm]
        \tikzstyle{level 3}=[level distance=1.5cm, sibling distance=1cm]
        \tikzstyle{level 4}=[level distance=1.5cm, sibling distance=2cm]
            \begin{tikzpicture}
            \node {p}
                child{
                    child{
                        node(a){c}
                    } child{edge from parent[draw=none] }
                }
                child{
                    node{}
                    child{
                        node(b){d}
                    }
                    child{
                        node(c){e}
                    }
                };
            \end{tikzpicture}
        \end{center}
    \end{figure}
\end{document}

enter image description here

Credits to this page.

share|improve this answer

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.