在 TiKZ 中对齐两棵树(状态/节点)

在 TiKZ 中对齐两棵树(状态/节点)

在下图中,我想将树与状态 11、12、13、14 对齐,使得 11-14 形成一个垂直链,其中状态 11 位于状态 1 的右侧,状态 12 位于状态 3 的右侧,状态 13 位于状态 6 的右侧,状态 14 位于状态 10 的右侧。我该怎么做呢?

\documentclass{article}

\usepackage{tikz}
\usepackage{amsmath}
\usetikzlibrary{automata}
\usetikzlibrary{calc,arrows.meta,positioning}

\newcommand{\iddots}{\reflectbox{$\ddots$}}
\begin{document}

\resizebox{\textwidth}{!}{
\begin{tikzpicture}[->,-latex,shorten >=1pt,auto,node distance=40mm,semithick, state/.style={circle, draw, minimum size=2cm}]
\node[state](1)                  {$S_0$};
\node[state](2)[below left  of=1] {$d\cdot S_0$};
\node[state](3)[below right of=1]{$u \cdot S_0$};
\node[state](4)[below left  of=2] {$d^2 \cdot S_0$};
\node[state](5)[below right of=2]{$du \cdot S_0$};
\node[state](6)[below right of=3]{$u^2 \cdot S_0$};
\node[state](7)[below left of=4]{$d^N \cdot S_0$};
\node[state](8)[below right of=4]{$d^k u^{N-k} \cdot S_0$};
\node[state](9)[below right of=5]{$d^{N-k}u^{k}\cdot S_0$};
\node[state](10)[below right of=6]{$u^N \cdot S_0$};
\node[state](14)[right of=10]{$S_1$};
\node[state](13)[above of=14, right of=6]{$S_1$};
\node[state](12)[above of=13, right of=3]{$S_1$};
\node[state](11)[above of=12, right of=1]{$S_1$};

\path (1) edge [swap] node {$1-p$}(2)
      (1) edge        node {$p$}(3)
      (2) edge [swap] node {$1-p$}(4)
      (2) edge        node {$p$}(5)
      (3) edge [swap] node {$1-p$}(5)
      (3) edge        node {$p$}(6);
       \node at ($(7)!.5!(8)$) {$\hdots$};
       \node at ($(8)!.5!(9)$) {$\hdots$};
       \node at ($(9)!.5!(10)$) {$\hdots$};
       
       \node at ($(4)!.5!(7)$) {\iddots};
       \node at ($(5)!.5!(8)$) {\iddots};
       \node at ($(6)!.5!(9)$) {\iddots};
       
       \node at ($(4)!.5!(8)$) {$\ddots$};
       \node at ($(5)!.5!(9)$) {$\ddots$};
       \node at ($(6)!.5!(10)$) {$\ddots$};
\end{tikzpicture}
}
\end{document}

我想要的(或多或少): 期望输出

答案1

正如我在评论中提到的,如果您有两个节点,您可以“计算”一个假想矩形的角,并将-|一个节点放置在这个位置。在您的例子中,您有节点 (14) 和 (1)、(3)、(6),您可以在其中将其他节点对齐到所需的位置。

在此处输入图片描述

\documentclass[border=5pt]{standalone}

\usepackage{tikz}
\usepackage{amsmath}
\usetikzlibrary{automata}
\usetikzlibrary{calc,arrows.meta,positioning}

\newcommand{\iddots}{\reflectbox{$\ddots$}}
\begin{document}
    
    \resizebox{\textwidth}{!}{
        \begin{tikzpicture}[->,-latex,shorten >=1pt,auto,node distance=40mm,semithick, state/.style={circle, draw, minimum size=2cm}]
            \node[state](1)                  {$S_0$};
            \node[state](2)[below left  of=1] {$d\cdot S_0$};
            \node[state](3)[below right of=1]{$u \cdot S_0$};
            \node[state](4)[below left  of=2] {$d^2 \cdot S_0$};
            \node[state](5)[below right of=2]{$du \cdot S_0$};
            \node[state](6)[below right of=3]{$u^2 \cdot S_0$};
            \node[state](7)[below left of=4]{$d^N \cdot S_0$};
            \node[state](8)[below right of=4]{$d^k u^{N-k} \cdot S_0$};
            \node[state](9)[below right of=5]{$d^{N-k}u^{k}\cdot S_0$};
            \node[state](10)[below right of=6]{$u^N \cdot S_0$};
            \node[state](14)[right of=10]{$S_1$};
            \node[state](13) at (6-|14) {$S_1$};
            \node[state](12) at (3-|14) {$S_1$};
            \node[state](11) at (1-|14) {$S_1$};
            
            \path (1) edge [swap] node {$1-p$}(2)
            (1) edge        node {$p$}(3)
            (2) edge [swap] node {$1-p$}(4)
            (2) edge        node {$p$}(5)
            (3) edge [swap] node {$1-p$}(5)
            (3) edge        node {$p$}(6);
            \node at ($(7)!.5!(8)$) {$\hdots$};
            \node at ($(8)!.5!(9)$) {$\hdots$};
            \node at ($(9)!.5!(10)$) {$\hdots$};
            
            \node at ($(4)!.5!(7)$) {\iddots};
            \node at ($(5)!.5!(8)$) {\iddots};
            \node at ($(6)!.5!(9)$) {\iddots};
            
            \node at ($(4)!.5!(8)$) {$\ddots$};
            \node at ($(5)!.5!(9)$) {$\ddots$};
            \node at ($(6)!.5!(10)$) {$\ddots$};
        \end{tikzpicture}
    }
\end{document}

相关内容