博弈论树,实体节点大小

博弈论树,实体节点大小

我对 latex 还比较陌生,而且在 overleaf 上工作(不知道这是否有帮助?)。我正在尝试创建一个游戏树。目前我遇到了一些问题。

  1. 我不确定如何指定节点的大小(以使其足够小以至于看起来像一个节点而不是一个巨大的圆圈)。

  2. 我想将“自然”、“P1”、“P2”等等变成圆圈(空心)。

  3. 我不确定如何在列而不是行中写终端节点中的数字,并且 \ 命令没有帮助。

  4. 我真的很想倾斜树的第二、第三和第四级边缘,即通向最后 2 个“P2”的长边缘,以便后者彼此更接近,但我似乎没有找到这样做的方法。

  5. 有没有办法使特定边缘变厚或加倍而不是着色?

提前致谢。

以下是我目前所掌握的信息:

\documentclass[11pt]{article}
\usepackage[utf8]{inputenc}
\usepackage{multirow}
\usepackage[margin=1in]{geometry} 
\usepackage{amsmath,amsthm,amssymb,amsfonts}
 \usepackage{tikz}   %for game theory stuff
\usetikzlibrary{calc}


\newcommand{\overbar}[1]{\mkern 1.5mu\overline{\mkern-1.5mu#1\mkern-1.5mu}\mkern 1.5mu}

\newenvironment{problem}[2][Problem]{\begin{trivlist}
\item[\hskip \labelsep {\bfseries #1}\hskip \labelsep {\bfseries #2.}]}{\end{trivlist}}


\title{Math 350 \\ Homework 4}
\author{Elen Khachatran}
\date\today


\begin{document}
\maketitle


\begin{figure}
    \centering
    \caption{Caption}

    \begin{tikzpicture}[scale=1,font=\footnotesize]
\tikzstyle{solid node}=[circle,draw,inner sep=1.2,fill=black];
    \tikzstyle{hollow node}=[circle,draw,inner sep=1.2];
\tikzstyle{level 1}=[level distance=30mm,sibling distance=30mm]
\tikzstyle{level 2}=[level distance=25mm,sibling distance=10mm]
\tikzstyle{level 3}=[level distance=20mm,sibling distance=10mm]
\tikzstyle{level 4}=[level distance=20mm,sibling distance=50mm]
\tikzstyle{level 5}=[level distance=28mm,sibling distance=25mm]
 \tikzstyle{level 6}=[level distance=28mm,sibling distance=50mm]   
    \node {Nature}
    child {node (1){P1} 
      child {node (7){$-1, 1$}
            edge from parent 
  node[left, pos=0.6, xshift=-2] {c}
            }
    child {
    child{ 
    child{node(8)[right, pos=0.6, xshift=-5]{P2} 
    child {node(27){$1,-1$}
    edge from parent 
  node[right, pos=0.6, xshift=-15] {f}}
    child {node (28){$-2,2$}
    edge from parent 
  node[right, pos=0.6, xshift=2] {c}}}
    edge from parent 
  node[right, pos=0.6, xshift=2] {r}}
    } 
  edge from parent 
  node[left, pos=0.6, xshift=-5] {$JQK$}
  node[left, pos=0.2, xshift=-5] {$ p_1 $}
  }
    child {node (2){P1} 
        child {node (9){$-1, 1$}
            edge from parent 
  node[right, pos=0.6, xshift=-15] {c}}
        child {node(10){P2} 
            child {node (19){$1,-1$} 
            edge from parent 
  node[right, pos=0.6, xshift=-15] {f}}
            child {node (20){$-2,2$}
            edge from parent 
  node[right, pos=0.6, xshift=2] {c}}
            edge from parent 
  node[right, pos=0.6, xshift=2] {r}}
  edge from parent 
  node[right, pos=0.6, xshift=-5] {$JKQ$}
  node[right, pos=0.2, xshift=-5] {$p$}
  }
   child {node (3){P1} 
      child {node (11){P2}
            child {node (21){$1,-1$}
            edge from parent 
  node[right, pos=0.6, xshift=-12] {f}}
            child {node (22){$-2,2$}
            edge from parent 
  node[right, pos=0.6, xshift=2] {c}}
            edge from parent 
  node[right, pos=0.6, xshift=-15] {r}}
    child {node(12){$-1,1$} 
    edge from parent 
  node[right, pos=0.6, xshift=2] {c}}
  edge from parent 
  node[right, pos=0.6, xshift=-5] {$QKJ$}
  node[right, pos=0.2, xshift=-5] {$p$}
  } 
   child {node (4){P1} 
      child {node (13){$1,-1$}
            edge from parent 
  node[right, pos=0.6, xshift=-15] {c}
            }
    child {node(14){P2} 
            child {node (23) {$1,-1$}
            edge from parent 
  node[right, pos=0.6, xshift=-15] {f}}
            child {node (24) {$2,-2$}
            edge from parent 
  node[right, pos=0.6, xshift=2] {c}}
            edge from parent 
  node[right, pos=0.6, xshift=2] {r}}
  edge from parent 
  node[right, pos=0.6, xshift=-5] {$QJK$}
  node[right, pos=0.2, xshift=-5] {$ p$}
  } 
   child {node (5){P1} 
      child {node (15){P2}
            child {node (25) {$1,-1$}
            edge from parent 
  node[right, pos=0.6, xshift=-15] {f}}
            child {node (26) {$2,-2$}
            edge from parent 
  node[right, pos=0.6, xshift=2] {c}}
            edge from parent 
  node[right, pos=0.6, xshift=-15] {r}}
    child {node(16){$1,-1$} 
    edge from parent 
  node[right, pos=0.6, xshift=2] {c}}
  edge from parent 
  node[right, pos=0.6, xshift=-5] {$KJQ$}
  node[right, pos=0.2, xshift=-5] {$p$}
  } 
   child {node (6){P1} 
      child{
      child{
      child {node (17){P2}
            child {node (27)[solid node]{$1,-1$}
            edge from parent 
  node[right, pos=0.6, xshift=-15] {r}}
            child {node{$2,-2$}
            edge from parent 
  node[right, pos=0.6, xshift=2] {c}}
            }edge from parent 
  node[right, pos=0.6, xshift=-15] {r}}}
    child {node(18){$1,-1$} 
    edge from parent 
  node[right, pos=0.6, xshift=2] {c}}
  edge from parent 
  node[right, pos=0.6, xshift=-5] {$KQJ$}
  node[right, pos=0.2, xshift=-5] {$p$}
  }; 
\draw[dashed,-] (1) -- (2);    
 \draw[dashed,-] (3) -- (4);
 \draw[dashed,-] (5) -- (6);
  \draw[dashed,-] (10) -- (11);  
  \draw[dashed,-] (14) -- (15);      
  \draw[dashed,-] (8) -- (17);    

    \end{tikzpicture}
\end{figure}

\end{document}

在此处输入图片描述

答案1

另一种解决方案是使用istgame包(版本 2)。

在此处输入图片描述

\documentclass{standalone}

\usepackage{amsmath}
\def\vpay#1#2{\begin{matrix}#1\\#2\end{matrix}}

\usepackage{istgame}

\begin{document}

\begin{istgame}[scale=.8,font=\footnotesize]
\xtShowEndPoints % solid nodes
\setistEllipseNodeStyle{6mm} % minimum circle size for players
\xtdistance{30mm}{30mm}
\istrooto(0){Nature}
  \istB{JQK}[l]{p_1}[left,near start,xshift=-5pt]
  \istB{JKQ}[l]{p}[left,near start]
  \istB{QJK}[l]{p}[left,near start]
  \istB{QJK}[r]{p}[right,near start]
  \istB{KJQ}[r]{p}[right,near start,xshift=5pt]
  \istB{KQJ}[r]{p}[right,near start,xshift=5pt]
  \endist
\xtdistance{25mm}{10mm}
\istrooto(1)(0-1){$P_1$}
  \istb{c}[l]{\vpay{-1}{1}} \istb<grow=-70,level distance=90mm>{r}[r] \endist
\istrooto(2)(0-2){$P_1$}
  \istb{c}[l]{\vpay{-1}{1}} \istb{r}[r] \endist
\istrooto(3)(0-3){$P_1$}
  \istb{r}[l] \istb{c}[r]{\vpay{-1}{1}} \endist
\istrooto(4)(0-4){$P_1$}
  \istb{c}[l]{\vpay{1}{-1}} \istb{r}[r] \endist
\istrooto(5)(0-5){$P_1$}
  \istb{r}[l] \istb{c}[r]{\vpay{1}{-1}} \endist
\istrooto(6)(0-6){$P_1$}
  \istb<grow=-110,level distance=90mm>{r}[l] \istb{c}[r]{\vpay{1}{-1}} \endist
\xtdistance{20mm}{10mm}
\istrooto(a)(2-2){$P_2$}
  \istb{f}[l]{\vpay{1}{-1}} \istb{c}[r]{\vpay{-2}{2}} \endist
\istrooto(b)(3-1){$P_2$}
  \istb{f}[l]{\vpay{1}{-1}} \istb{c}[r]{\vpay{-2}{2}} \endist
\istrooto(c)(4-2){$P_2$}
  \istb{f}[l]{\vpay{1}{-1}} \istb{c}[r]{\vpay{2}{-2}} \endist
\istrooto(d)(5-1){$P_2$}
  \istb{f}[l]{\vpay{1}{-1}} \istb{c}[r]{\vpay{2}{-2}} \endist
\xtdistance{28mm}{25mm}
\istrooto(A)(1-2){$P_2$}
  \istb[draw=red]{f}[l]{\vpay{1}{-1}} \istb[draw=blue]{c}[r]{\vpay{-2}{2}} \endist
\istrooto(B)(6-1){$P_2$}
  \istb[double]{f}[l]{\vpay{1}{-1}} \istb[ultra thick]{c}[r]{\vpay{2}{-2}} \endist
% information sets
\setxtinfosetstyle{dashed}
\xtInfoset(1)(2)
\xtInfoset(3)(4)
\xtInfoset(5)(6)
\xtInfoset(a)(b)
\xtInfoset(c)(d)
\xtInfoset(A)(B)
\end{istgame}

\end{document}

答案2

我尝试清理代码并向hn圆形节点添加选项(空心节点)。对于根节点,我建议使用圆角矩形。我不会将末端节点放在圆形中,最终我会添加灰色背景(在姆韦下面显示了最后两个端节点)。如果你喜欢这样的解决方案,你只需要gn为所有端节点添加节点样式(灰色节点)。

由于树形图非常宽,我将页面边框缩小到 20 毫米。我还从序言中删除了所有与树形图无关的内容。

\documentclass[11pt]{article}
\usepackage[margin=20mm]{geometry}
\usepackage[skip=1ex]{caption}
\usepackage{tikz}   %for game theory stuff

%---------------- show page layout. don't use in a real document!
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%---------------------------------------------------------------%

\begin{document}

\begin{figure}
    \centering
    \caption{Caption}

    \begin{tikzpicture}[
          font = \footnotesize,
     hn/.style = {circle, draw},
     gn/.style = {rounded corners, fill=gray!20, inner xsep=2pt},
level 1/.style = {level distance = 30mm,sibling distance=31mm},
level 2/.style = {level distance = 20mm,sibling distance=10mm},
level 4/.style = {level distance =  5mm},
level 5/.style = {level distance = 20mm}
                        ]
\node[draw, rounded corners] {Nature}
    child {node (1) [hn] {P1}
      child {node (7) {$-1, 1$}
            edge from parent node[left] {c}
            }
    child {
        child{
            child{ node (8) [hn] {P2}
        child {node (27) {$1,-1$}
            edge from parent node[left] {f}}
        child {node (28){$-2,2$}
            edge from parent node[right] {c}}
                }
        edge from parent node[right] {r}}
            }
    edge from parent node[left=1mm] {$JQK$}
                     node[left=1mm, pos=0.25] {$p_1$}
        }
    child {node (2) [hn] {P1}
        child {node (9) {$-1, 1$}
            edge from parent node[right] {c}
               }
        child {node (10) [hn] {P2}
            child {node (19) {$1,-1$}
                edge from parent node[right, pos=0.6, xshift=-15] {f}}
            child {node (20) {$-2,2$}
                edge from parent node[right, pos=0.6, xshift=2] {c}
                  }
            edge from parent node[right, pos=0.6, xshift=2] {r}
            }
        edge from parent node[left=1mm] {$JKQ$}
                         node[left=1mm, pos=0.3] {$p$}
            }
   child {node (3) [hn] {P1}
      child {node (11) [hn] {P2}
        child {node (21) {$1,-1$}
            edge from parent node[right=1mm] {f}}
            child {node (22) {$-2,2$}
                edge from parent node[right=1mm] {c}}
            edge from parent node[right=1mm] {r}}
    child {node(12) {$-1,1$}
        edge from parent node[right, pos=0.6, xshift=2] {c}
           }
        edge from parent node[left=1mm] {$QKJ$}
                         node[left=1mm, pos=0.35] {$p$}
        }
   child {node (4) [hn] {P1}
      child {node (13) {$1,-1$}
        edge from parent node[right=1mm] {c}
            }
    child {node(14) [hn] {P2}
        child {node (23) {$1,-1$}
            edge from parent node[right=1mm] {f}}
            child {node (24) {$2,-2$}
                edge from parent node[right=1mm] {c}
                }
            edge from parent node[right=1mm] {r}
            }
        edge from parent node[right=1mm] {$QJK$}
                         node[right=1mm, pos=0.35] {$ p$}
        }
    child {node (5) [hn] {P1}
        child {node (15) [hn] {P2}
            child {node (25){$1,-1$}
                edge from parent node[right=1mm] {f}
                  }
            child {node (26) {$2,-2$}
                edge from parent node[right=1mm] {c}
                  }
            edge from parent node[right=1mm] {r}}
            child {node(16) {$1,-1$}
                edge from parent node[right=1mm] {c}
                 }
            edge from parent node[right=1mm] {$KJQ$}
                             node[right=1mm, pos=0.3] {$p$}
        }
   child {node (6) [hn] {P1}
      child{
        child{
            child {node (17) [hn] {P2}
            child {node (27) [gn]  {$1,-1$}
                edge from parent node[right=1mm] {r}
                    }
            child {node [gn] {$2,-2$}
                edge from parent node[right=1mm] {c}
                    }
                }
        edge from parent node[right=1mm] {r}
            }}
    child {node(18) {$1,-1$}
        edge from parent node[right=1mm] {c}
            }
        edge from parent node[right=1mm] {$KQJ$}
                         node[right=1mm,pos=0.25] {$p$}
        };
\draw[dashed]   (1)  -- (2)
                (3)  -- (4)
                (5)  -- (6)
                (10) -- (11)
                (14) -- (15)
                (8)  -- (17);
    \end{tikzpicture}
\end{figure}

在此处输入图片描述

(红线表示文本边框)

相关内容