使用 TikZ 在 LaTeX 中生成决策树

使用 TikZ 在 LaTeX 中生成决策树

不必包含网格线

在此处输入图片描述

\documentclass[10pt]{beamer} 
\usetheme{default} 
\usepackage{graphicx} 
\usepackage{amssymb,amsmath} 
\usepackage{tikz} 
\usetikzlibrary{matrix} 
\usepackage{adjustbox} 
\usepackage{caption} \
usepackage{subcaption}  
\setbeamercolor{title}{fg=black} 
\setbeamercolor{subtitle}{fg=gray} 
\setbeamercolor{footlinecolor}{fg=white,bg=green} 
\setbeamertemplate{footline}[text line]{% \parbox{\linewidth}{\vspace*{-10pt} \textit{Where Wall Street Goes to School} \hfill \insertpagenumber} } \setbeamertemplate{navigation symbols}{} –

\begin{tikzpicture}[>=stealth,sloped][scale=0.8] 
\matrix (tree) [matrix of nodes, minimum size=0.25cm, column sep=2cm, row sep=1cm, ] 
{ & $C_{i+1,j+1}$ \\ $C_{i,j}$ &$C_{i+1,j}$ \\ 
& $C_{i+1,j-1}$ \\  
}; 
\draw[->] (tree-3-1) -- (tree-1-3) node [midway,above] {}; 
\draw[->] (tree-3-1) -- (tree-3-3) node [midway,above] {}; 
\draw[->] (tree-3-1) -- (tree-5-3) node [midway,below] {}; 
\end{tikzpicture} 
\end{adjustbox} –

答案1

尝试

\documentclass[tikz, margin=3mm]{standalone}
\usetikzlibrary{arrows.meta, matrix}

\begin{document}
    \begin{tikzpicture}[
every edge/.append style = {-Straight Barb, thick,
                            shorten >=1mm, shorten <=1mm},
                        ]
\matrix (tree) [matrix of nodes,
                nodes={circle, draw, minimum size=3mm, inner sep=0mm},
                column sep=2cm, row sep=1cm
                ]
{
|[label=left:{$C_{i,j+1}$}]|  &   |[label=right:{$C_{i+1,j+1}$}]|   \\
|[label=left:{$C_{i,j}$}]|    &   |[label=right:{$C_{i+1,j}$}]|     \\
|[label=left:{$C_{i,j-1}$}]|  &   |[label=right:{$C_{i+1,j-1}$}]|   \\  
};
\path   (tree-1-1) edge (tree-2-2)
        (tree-2-1) edge (tree-2-2)
        (tree-3-1) edge (tree-2-2)
        (tree-1-2) edge (tree-2-2)
        (tree-3-2) edge (tree-2-2);

    \end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容