Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

This is a really tough problem that I have no idea how to solve. I wish to have a dotted veritcal line in the middle of my binomial tree, with a $\tau$ underneath.. The kind of thing I want is as follows:

enter image description here

The code for the image WITHOUT this line (or the associated \tau) is as follows:

 \documentclass{article}

 \usepackage{tikz}
 \usetikzlibrary{matrix,fit,backgrounds}



  \begin{document}


 \begin{tikzpicture}[>=stealth,sloped]
    \matrix (tree) [%
      matrix of nodes,
      minimum size=1cm,
      column sep=2.5cm,
      row sep=0.4cm,
    ]
    {  
              &                    &                     &  $_\tau S_0$             \\
              &                    &  $_{2\Delta t}S_0$  &                  \\
              & $_{\Delta t}S_0$   &                     &  $_\tau S_1$             \\
      $_0S_0$ &                    &  $_{2\Delta t}S_1$  &                  \\
              & $_{\Delta t}S_1$   &                      &  $_\tau S_2$         \\
              &                    &  $_{2\Delta t}S_2$  &                \\
              &                    &                     &  $_\tau S_3$    \\
    };

    \draw[->] (tree-4-1) -- (tree-3-2) node [midway,above] {$p$};
    \draw[->] (tree-4-1) -- (tree-5-2) node [midway,below] {$1-p$};
    \draw[->] (tree-3-2) -- (tree-2-3) node [midway,above] {};
    \draw[->] (tree-3-2) -- (tree-4-3) node [midway,below] {};
    \draw[->] (tree-5-2) -- (tree-4-3) node [midway,above] {};
    \draw[->] (tree-5-2) -- (tree-6-3) node [midway,below] {};

    \draw[->] (tree-2-3) -- (tree-1-4) node [midway,above] {};
    \draw[->] (tree-2-3) -- (tree-3-4) node [midway,below] {};
    \draw[->] (tree-4-3) -- (tree-3-4) node [midway,above] {};
    \draw[->] (tree-4-3) -- (tree-5-4) node [midway,below] {};
    \draw[->] (tree-6-3) -- (tree-5-4) node [midway,above] {};
    \draw[->] (tree-6-3) -- (tree-7-4) node [midway,below] {};

  \end{tikzpicture}

  \end{document}
share|improve this question
1  
Notice that you could use math of matrix nodes and avoid some $ inside the matrix. –  Claudio Fiandrino Sep 8 '12 at 13:02

2 Answers 2

up vote 3 down vote accepted

The calc library makes this an easy task, but you have to assign names to empty matrix cells:

\usetikzlibrary{calc}
\begin{tikzpicture}[>=stealth,sloped]
    \matrix (tree) [%
      matrix of nodes,
      minimum size=1cm,
      column sep=2.5cm,
      row sep=0.4cm,
    ]
    {  
              & |(top-left)|                   & |(top-right)|                     &  $_\tau S_0$             \\
              &                    &  $_{2\Delta t}S_0$  &                  \\
              & $_{\Delta t}S_0$   &                     &  $_\tau S_1$             \\
      $_0S_0$ &                    &  $_{2\Delta t}S_1$  &                  \\
              & $_{\Delta t}S_1$   &                      &  $_\tau S_2$         \\
              &                    &  $_{2\Delta t}S_2$  &                \\
              & |(bottom-left)|                   & |(bottom-right)|                    &  $_\tau S_3$    \\
    };

    \draw[->] (tree-4-1) -- (tree-3-2) node [midway,above] {$p$};
    \draw[->] (tree-4-1) -- (tree-5-2) node [midway,below] {$1-p$};
    \draw[->] (tree-3-2) -- (tree-2-3) node [midway,above] {};
    \draw[->] (tree-3-2) -- (tree-4-3) node [midway,below] {};
    \draw[->] (tree-5-2) -- (tree-4-3) node [midway,above] {};
    \draw[->] (tree-5-2) -- (tree-6-3) node [midway,below] {};

    \draw[->] (tree-2-3) -- (tree-1-4) node [midway,above] {};
    \draw[->] (tree-2-3) -- (tree-3-4) node [midway,below] {};
    \draw[->] (tree-4-3) -- (tree-3-4) node [midway,above] {};
    \draw[->] (tree-4-3) -- (tree-5-4) node [midway,below] {};
    \draw[->] (tree-6-3) -- (tree-5-4) node [midway,above] {};
    \draw[->] (tree-6-3) -- (tree-7-4) node [midway,below] {};

    % τ-line
    \draw[dashed] ($(top-left.north)!.5!(top-right.north)$) -- ($(bottom-left.south)!.5!(bottom-right.south)$);
    \node at ($(bottom-left.south)!.5!(bottom-right.south)-(0,1em)$) {$\tau$};

  \end{tikzpicture}
share|improve this answer
    
I think you're missing some $ signs in the last few lines of your code which means I can't run it. –  user16208 Sep 8 '12 at 12:59
    
@IssacM: yeah, I forgot to delimit the calc expressions. Fixed now (also added names to empty cells) –  knittl Sep 8 '12 at 13:05

You can use orthogonal intersections via |- and -| coordinate qualifiers.

\documentclass{article}

\usepackage{tikz}
\usetikzlibrary{matrix,fit,backgrounds}



\begin{document}


 \begin{tikzpicture}[>=stealth,sloped]
    \matrix (tree) [%
      matrix of nodes,
      minimum size=1cm,
      column sep=2.5cm,
      row sep=0.4cm,
    ]
    {  
              &                    &                     &  $_\tau S_0$             \\
              &                    &  $_{2\Delta t}S_0$  &                  \\
              & $_{\Delta t}S_0$   &                     &  $_\tau S_1$             \\
      $_0S_0$ &                    &  $_{2\Delta t}S_1$  &                  \\
              & $_{\Delta t}S_1$   &                      &  $_\tau S_2$         \\
              &                    &  $_{2\Delta t}S_2$  &                \\
              &                    &                     &  $_\tau S_3$    \\
    };

    \draw[->] (tree-4-1) -- (tree-3-2) node [midway,above] {$p$};
    \draw[->] (tree-4-1) -- (tree-5-2) node [midway,below] {$1-p$};
    \draw[->] (tree-3-2) -- (tree-2-3) node [midway,above] (a) {};
    \draw[->] (tree-3-2) -- (tree-4-3) node [midway,below] {};
    \draw[->] (tree-5-2) -- (tree-4-3) node [midway,above] {};
    \draw[->] (tree-5-2) -- (tree-6-3) node [midway,below] {};

    \draw[->] (tree-2-3) -- (tree-1-4) node [midway,above] {};
    \draw[->] (tree-2-3) -- (tree-3-4) node [midway,below] {};
    \draw[->] (tree-4-3) -- (tree-3-4) node [midway,above] {};
    \draw[->] (tree-4-3) -- (tree-5-4) node [midway,below] {};
    \draw[->] (tree-6-3) -- (tree-5-4) node [midway,above] {};
    \draw[->] (tree-6-3) -- (tree-7-4) node [midway,below] {};

\draw[dashed] (tree-7-4 -| a) -- (tree-1-4 -| a);
  \end{tikzpicture}

  \end{document}

enter image description here

share|improve this answer
1  
This is good! (+1) Had I only known this a while back, when I needed this myself. I used the calc library instead to achieve the same effect –  knittl Sep 8 '12 at 13:13
2  
@knittl Thanks. I would also suggest you to use nodes in empty cells option to populate the names of the empty entries in your solution. Then regular (matrixname-row-col) naming works also for the empty cells. –  percusse Sep 8 '12 at 13:16
1  
Yeah, but nodes in empty cells often has side effects (i.e. when you apply a style to all cells). I'm sure there's a way round it, I just don't know it … –  knittl Sep 8 '12 at 13:18
1  
@knittl Indeed, the relevant key is the execute at empty cell :) You can check in the manual to override the settings for empty cells –  percusse Sep 8 '12 at 13:19

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.