这是一个非常棘手的问题,我不知道如何解决。我希望在二叉树的中间有一条虚线,下面有一个$\tau$
……我想要的东西如下:
没有此行(或相关的 \tau)的图像代码如下:
\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}
答案1
该calc
库使这成为一项简单的任务,但您必须为空矩阵单元分配名称:
\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}
答案2
|-
您可以通过和-|
坐标限定符使用正交交叉。
\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}