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

How can I set the path between two specific nodes to "vertical" rather than "direct"?

Currently my tree looks like this:

\begin{tikzpicture}[level distance=1.5cm,
    every node/.style={draw=black,very thick,minimum width=10mm,inner sep=2mm},
    every path/.style={thick},
    level 1/.style={sibling distance=4cm},
    level 2/.style={sibling distance=2cm},
    level 3/.style={sibling distance=0.5cm,level distance=10mm},
    leaf/.style={fill=black,minimum width=2mm,minimum height=2mm,inner sep=0mm}]
            child{node{21 29}
                child[edge from parent]{node[leaf]{}}


I would like to have the paths between the last row and the leafs to be vertical, rather than diagonal.

share|improve this question
up vote 5 down vote accepted

You can change the way edges are drawn with the edge from parent path key. Change the level 3/.style line to:

level 3/.style={
    sibling distance=0.5cm,
    level distance=10mm,
    edge from parent path={
        (\tikzchildnode.north) -- (\tikzchildnode.north |- \tikzparentnode.south)

If A and B are coordinates, then A |- B is the intersection of a vertical line through A and a horizontal line through B. So (A) -- (A |- B) draws a line to this intersection.

sample code output

If you're going to do this a lot, make your own style:

\tikzset{edge from parent vertical/.style={
   edge from parent path={
       (\tikzchildnode.north) -- (\tikzchildnode.north |- \tikzparentnode.south)

then you can change the line to:

level 3/.style={sibling distance=0.5cm,level distance=10mm,edge from parent vertical}
share|improve this answer
Great explanation of the solution. Thanks! – Manuel Faux May 16 '13 at 17:40
The |- syntax is a solution to many problems. Thank for pointing at it. – Alfred M. Mar 31 at 12:55

Your Answer


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.