二项树中的垂直线破坏了节点着色

二项树中的垂直线破坏了节点着色

如何阻止虚拟节点被着色?

在此处输入图片描述

\documentclass{article}

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



  \begin{document}

 \begin{tikzpicture}[>=stealth,sloped]
     \matrix (tree) [%
       matrix of nodes,
       minimum size=1cm,
       column sep=2.5cm,
       row sep=0.4cm,
      column 2/.style={nodes={draw,fill=green!30,rounded corners}},
       column 3/.style={nodes={draw,fill=red!30,rounded corners}},
     ]
     {
               & |(top-left)|       & |(top-right)|       &  $_0 S_T$             \\
               &                    &  $_0S_{2\Delta t}$  &                  \\
               & $_0S_{\Delta t}$   &                     &  $_1 S_T$             \\
       $_0S_0$ &                    &  $_1S_{2\Delta t}$  &                  \\
               & $_1S_{\Delta t}$   &                     &  $_2 S_T$         \\
               &                    &  $_2S_{2\Delta t}$  &                \\
               & |(bottom-left)|    & |(bottom-right)|    &  $_3 S_T$    \\
     };

     \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] {};

     % t-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}

  \end{document}

答案1

您可以使用draw=nonefill=none。在这里,我将两者都放在一个名为的样式中dummy

代码

 \matrix (tree) [%
   matrix of nodes,
   minimum size=1cm,
   column sep=2.5cm,
   row sep=0.4cm,
   column 2/.style={nodes={draw,fill=green!30,rounded corners}},
   column 3/.style={nodes={draw,fill=red!30,rounded corners}},
   dummy/.style={fill=none,draw=none}
 ]
 {
           & |[dummy](top-left)|       & |[dummy](top-right)|       &  $_0 S_T$             \\
           &                    &  $_0S_{2\Delta t}$  &                  \\
           & $_0S_{\Delta t}$   &                     &  $_1 S_T$             \\
   $_0S_0$ &                    &  $_1S_{2\Delta t}$  &                  \\
           & $_1S_{\Delta t}$   &                     &  $_2 S_T$         \\
           &                    &  $_2S_{2\Delta t}$  &                \\
           & |[dummy](bottom-left)|    & |[dummy](bottom-right)|    &  $_3 S_T$    \\
 };

结果

在此处输入图片描述

相关内容