博弈论概率树,节点末端有表格

博弈论概率树,节点末端有表格

我想要一个贝叶斯博弈论问题的概率树,它看起来完全像这样:

在此处输入图片描述

这是我尝试编写的代码

*编辑一个更清晰的序言

    \documentclass[12pt, a4 paper]{article}

 \usepackage{multicol} %Needed for \PDgame
 \usepackage{multirow}
 \usepackage{wrapfig}
 \usepackage{tabu}
 \usepackage{mathtools}
 \usepackage{graphicx}
 \usepackage[english]{babel}
 \usepackage[utf8]{inputenc}
 \usepackage{amsmath,amssymb}
 \usepackage{parskip}
 \usepackage{graphicx}
 \usepackage{tabu}
 \usepackage{mathtools}
 \usepackage{graphicx}
 \usepackage{verbatim}
 \usepackage{subcaption}
 \usepackage{indentfirst}
 \usepackage{tikz}
 % Margins
 \usepackage[inner=2.0cm,outer=2.0cm,top=2.5cm,bottom=2.5cm]{geometry}
 % Colour table cells
 \usepackage[table]{xcolor}


 \setlength{\marginparwidth}{2cm}
 \begin{document}

 A FAILED ATTEMPT TO MAKE THE PROB TREE WITH JUST ONE TABLE

 \begin{center}
 \begin{tikzpicture}
 \node(0){root}
 child{node{child 1}
    child{node{
    \begin{tabular}{cc|c|c|c|}
        & \multicolumn{2}{c}{$Pr(\omega_1)=\frac{1}{2}$}& 
 \multicolumn2c{\color{blue}Player 2} \\
        & \multicolumn2c{} & \multicolumn1c{$p$} & \multicolumn1c{$1-p$} \\
        \cline{3-5}
        &&& $a_2$ & $b_2$ \\
        \cline{3-5}
        \multirow2*{\color{red}Player 1} &$q$ & $a_1$
        & $\textbf{(\color{red}{0}\color{black}, \color{blue} 
{0}\color{black})}$ 
        & $(\color{red}{6}\color{black}, \color{blue}{-3}\color{black})$ \\
        \cline{3-5}
        & $1 - q$ & $b_1$ 
        & $(\color{red}{-3} \color{black}, \color{blue}{6}\color{black})$ 
        & $(\color{red}{5} \color{black}, \color{blue}{5}\color{black})$ \\
        \cline{3-5}
    \end{tabular}
    }}
    }
child{node{child 2}
}
;
\end{tikzpicture}
\end{center}

 CODE OF THE TABLES NEEDED IN THE NODES

 TABLE 1

 \begin{center}
    \begin{tabular}{cc|c|c|c|}
        &  \multicolumn{2}{c}{$Pr(\omega_1)=\frac{1}{2}$} & 
 \multicolumn2c{\color{blue}Player 2} \\
        & \multicolumn2c{} & \multicolumn1c{$p$} & \multicolumn1c{$1-p$} \\
        \cline{3-5}
        &&& $a_2$ & $b_2$ \\
        \cline{3-5}
        \multirow2*{\color{red}Player 1} &$q$ & $a_1$
        & $\textbf{(\color{red}{0}\color{black}, \color{blue} 
{0}\color{black})}$ 
        & $(\color{red}{6}\color{black}, \color{blue}{-3}\color{black})$ \\
        \cline{3-5}
        & $1 - q$ & $b_1$ 
        & $(\color{red}{-3} \color{black}, \color{blue}{6}\color{black})$ 
        & $(\color{red}{5} \color{black}, \color{blue}{5}\color{black})$ \\
        \cline{3-5}
    \end{tabular}
\end{center}

and

TABLE 2

\begin{center}
    \begin{tabular}{cc|c|c|c|}
        &  \multicolumn{2}{c}{$Pr(\omega_1)=\frac{1}{2}$} & 
 \multicolumn2c{\color{blue}Player 2} \\
        & \multicolumn2c{} & \multicolumn1c{$p$} & \multicolumn1c{$1-p$} \\
        \cline{3-5}
        &&& $a_2$ & $b_2$ \\
        \cline{3-5}
        \multirow2*{\color{red}Player 1} &$q$ & $a_1$
        & $\textbf{(\color{red}{-20}\color{black}, \color{blue} 
{-20}\color{black})}$ 
        & $(\color{red}{-7}\color{black}, \color{blue}{-16}\color{black})$ 
 \\
        \cline{3-5}
        & $1 - q$ & $b_1$ 
        & $(\color{red}{-16} \color{black}, \color{blue}{-7}\color{black})$ 
        & $(\color{red}{-5} \color{black}, \color{blue}{-5}\color{black})$ 
 \\
        \cline{3-5}
    \end{tabular}
\end{center}



 \end{document}

答案1

起点:

在此处输入图片描述

\documentclass[12pt, a4paper]{article}

 \usepackage{multirow}  \usepackage[table]{xcolor}  \usepackage{tikz}  \usepackage[inner=2.0cm,outer=2.0cm,top=2.5cm,bottom=2.5cm]{geometry}  \setlength{\marginparwidth}{2cm}    \begin{document}


 \begin{center}  \small  \setlength{\tabcolsep}{5pt}  \begin{tikzpicture}[level distance=2cm,sibling distance=8.5cm]  \node(0){Z}
    child{node{
    \begin{tabular}{cc|c|c|c|}
        & \multicolumn{2}{c}{$Pr(\omega_1)=\frac{1}{2}$}&   \multicolumn2c{\color{blue}Player 2} \\
        & \multicolumn{2}{c}{} & \multicolumn{1}{c}{$p$} & \multicolumn{1}{c}{$1-p$} \\
        \cline{3-5}
        &&& $a_2$ & $b_2$ \\
        \cline{3-5}
        \multirow2*{\color{red}Player 1} &$q$ & $a_1$
        & $\textbf{(\color{red}{0}\color{black}, \color{blue}  {0}\color{black})}$ 
        & $(\color{red}{6}\color{black}, \color{blue}{-3}\color{black})$ \\
        \cline{3-5}
        & $1 - q$ & $b_1$ 
        & $(\color{red}{-3} \color{black}, \color{blue}{6}\color{black})$ 
        & $(\color{red}{5} \color{black}, \color{blue}{5}\color{black})$ \\
        \cline{3-5}
    \end{tabular}
    }} child{node{    \begin{tabular}{cc|c|c|c|}
        &  \multicolumn{2}{c}{$Pr(\omega_1)=\frac{1}{2}$} &   \multicolumn2c{\color{blue}Player 2} \\
        & \multicolumn{2}{c}{} & \multicolumn{1}{c}{$p$} & \multicolumn{1}{c}{$1-p$} \\
        \cline{3-5}
        &&& $a_2$ & $b_2$ \\
        \cline{3-5}
        \multirow2*{\color{red}Player 1} &$q$ & $a_1$
        & $\textbf{(\color{red}{-20}\color{black}, \color{blue}  {-20}\color{black})}$ 
        & $(\color{red}{-7}\color{black}, \color{blue}{-16}\color{black})$   \\
        \cline{3-5}
        & $1 - q$ & $b_1$ 
        & $(\color{red}{-16} \color{black}, \color{blue}{-7}\color{black})$ 
        & $(\color{red}{-5} \color{black}, \color{blue}{-5}\color{black})$   \\
        \cline{3-5}
    \end{tabular}} } ; \end{tikzpicture} \end{center}


 \end{document}

答案2

附带forest包装:

\documentclass[12pt]{article}
\usepackage[hmargin=2.0cm, vmargin=2.5cm,
            marginparwidth=2cm]{geometry} 
\usepackage{makecell, multirow}
\NewExpandableDocumentCommand\mcc{O{1}m}%
    {\multicolumn{#1}{c}{#2}}
\usepackage[table]{xcolor}
\usepackage{forest}
 
\begin{document}
    \begin{center}
\newcommand\B[1]{\textcolor{blue}{#1}}
\newcommand\R[1]{\textcolor{red}{#1}}
\setcellgapes{3pt}
\makegapedcells  
\small
\setlength{\tabcolsep}{3pt}
    \begin{forest}
for tree = {
%     where level=1{draw=gray, dashed}{},
     child anchor=north,
    l sep=15mm,
    s sep=2mm
            }
[Z, 
    [{\begin{tabular}{@{} cc|c|c|c|}
\mcc[2]{$Pr(\omega_1)=\frac{1}{2}$}
            &\mcc{} & \mcc[2]{\B{Player 2}}  \\
    \cline{4-5}
\mcc[2]{}   &       & $p$   & $1-p$         \\
    \cline{4-5}
\mcc[2]{}   &       & $a_2$ & $b_2$         \\
    \cline{3-5}
\multirow{2}{*}{\R{Player 1}} 
            & $q$   & $a_1$ & (\R{0},\B{0}) & (\R{6},\B{-3})    \\
    \cline{3-5}
            & $1-q$ & $b_1$ & (\R{-3},\B{6})& (\R{5},\B{5})     \\
    \cline{3-5}
            \end{tabular}}, 
    edge label={node[pos=0.6,anchor=south east]{$\omega_1$}}]
    [{\begin{tabular}{@{} cc|c|c|c|}
\mcc[2]{$Pr(\omega_2)=\frac{1}{2}$}           
            &\mcc{} & \mcc[2]{\B{Player 2}}  \\
    \cline{4-5}
\mcc[2]{}   &       & $p$   & $1-p$         \\
    \cline{4-5}
\mcc[2]{}   &       & $a_2$ & $b_2$         \\
    \cline{3-5}
\multirow{2}{*}{\R{Player 1}}
            & $q$   & $a_1$ & (\R{-20},\B{-20}) & (\R{-7},\B{-16})    \\
    \cline{3-5}
            & $1-q$ & $b_1$ & (\R{-16},\B{-7})  & (\R{-5},\B{-5})     \\
    \cline{3-5}
            \end{tabular}},xshift=-2em,
    edge label={node[pos=0.6,anchor=south west]{$\omega_2$}}]
]
\end{forest}
    \end{center}
\end{document}

在此处输入图片描述

相关内容