Tikz 树对齐方程

Tikz 树对齐方程

我如何对齐此图中的方程式?我尝试使用对齐环境,但它不起作用。以下是代码:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{matrix}
\usetikzlibrary{matrix,positioning}
\tikzset{bullet/.style={circle,fill,inner sep=2pt}}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\begin{document}
\begin{figure}[h]
    \centering
    \caption{hktkrkrkrrrkrkrkrkrk}
    \begin{tikzpicture}[>=stealth,sloped]
        \matrix (tree) [%
        matrix of nodes,
        minimum size=.2cm,
        column sep=1cm,
        row sep=.2cm,
        ]
        {
            &   & \(
            \begin{aligned}
                S_{uu} &= \$19.8375\\[-4pt]
                C_{uu} &= \$3.83750\\
            \end{aligned}\) \\
            & \(
            \begin{aligned}
                S_{u} &= \$17.25\\[-4pt]
                C_{u} &= \$1.876093565\\
                \Delta &= .88985507250
            \end{aligned}\) &   \\
            \(
            \begin{aligned}
                S_{0} &= \$15\\
                C_{0} &= \$.9171927207\\
                \Delta &= .50029161740
            \end{aligned}\)
            &   & \(
            \begin{aligned}
                S_{ud} &= \$15.525\\[-4pt]
                C_{ud} &= \$0\\
            \end{aligned}\) \\
            & \(
            \begin{aligned}
                S_{d} &= \$13.5\\[-4pt]
                C_{d} &= \$0\\
                \Delta &= 0
            \end{aligned}\) &   \\
            &   & \(
            \begin{aligned}
                S_{dd} &= \$12.15\\[-4pt]
                C_{dd} &= \$0\\
            \end{aligned}\) \\
        };
        \draw[-] (tree-3-1) -- (tree-2-2) node [midway,above] {};
        \draw[-] (tree-3-1) -- (tree-4-2) node [midway,below] {};
        \draw[-] (tree-2-2) -- (tree-1-3) node [midway,above] {};
        \draw[-] (tree-2-2) -- (tree-3-3) node [midway,below] {};
        \draw[-] (tree-4-2) -- (tree-3-3) node [midway,above] {};
        \draw[-] (tree-4-2) -- (tree-5-3) node [midway,below] {};
    \end{tikzpicture}
\end{figure}
\end{document}

请您帮助我解决该问题。在此处输入图片描述

答案1

您正在寻找这样的图表吗?

在此处输入图片描述

编辑: 您需要将矩阵中的“与”符号替换为,例如\&,以便与节点中的“与”符号区分开来。除此之外,在您的特定情况下,对于矩阵列中完美对齐的方程式,您还需要将节点锚定到西边:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{matrix,positioning}
\tikzset{bullet/.style={circle,fill,inner sep=2pt}}

\usepackage{amsmath, amssymb}
\usepackage{siunitx}

\begin{document}
    \begin{figure}[h]
    \centering
    \caption{hktkrkrkrrrkrkrkrkrk}
\begin{tikzpicture}
\matrix (tree) [matrix of math nodes,
                nodes = {anchor=west},
                column sep=1cm,
                row sep=.2cm,
                ampersand replacement=\&
                ]
{
    \&   \& \begin{aligned}
            S_{uu} & = \$ 19.8375  \\
            C_{uu} & = \$  3.83750 \\
          \end{aligned}                     \\
    \& \begin{aligned}
        S_{u}  & = \$17.25\\ 
        C_{u}  & = \$1.876093565\\
        \Delta & = .88985507250 \\
            \end{aligned}   \&              \\
\begin{aligned}
    S_{0} &= \$15\\
    C_{0} &= \$.9171927207\\
    \Delta &= .50029161740
\end{aligned}   \& \& \begin{aligned}
                        S_{ud} &= \$15.525\\%[-4pt]
                        C_{ud} &= \$0\\
                      \end{aligned}     \\
    \& \begin{aligned}
        S_{d} &= \$13.5\\[-4pt]
        C_{d} &= \$0\\
        \Delta &= 0
     \end{aligned}  \&                  \\
    \&  \& \begin{aligned}
                    S_{dd} &= \$12.15\\[-4pt]
                    C_{dd} &= \$0\\
               \end{aligned}                \\
        };
\draw   (tree-3-1) -- (tree-2-2)
        (tree-3-1) -- (tree-4-2)
        (tree-2-2) -- (tree-1-3)
        (tree-2-2) -- (tree-3-3)
        (tree-4-2) -- (tree-3-3)
        (tree-4-2) -- (tree-5-3);
\end{tikzpicture}
    \end{figure}
\end{document}

相关内容