虚线边和交叉节点的问题

虚线边和交叉节点的问题

以下代码构建了一个带有一些虚线边和十字节点的游戏树。我唯一担心的是节点 2.3:如何避免虚线边和十字符号之间的重叠?

\documentclass[tikz,border=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning, calc}
\usetikzlibrary{shapes.misc}

% Node styles
\tikzset{
% Two node styles for game trees: solid and hollow
solid node/.style={circle,draw = black,inner sep=1.5,fill=black},
cross/.style={cross out, draw=black, ultra thick, minimum size=2*(#1-\pgflinewidth), inner sep=1.5, outer sep=0pt},
emph/.style={edge from parent/.style={directed,ultra thick,draw}},
norm/.style={edge from parent/.style={black,thin,draw}},
dashdot/.style={edge from parent/.style={dashdotted,thin,draw}}
}

\begin{document}

\begin{tikzpicture}[thin,
level 1/.style={level distance=15mm,sibling distance=55mm},
level 2/.style={level distance=15mm,sibling distance=27mm},
level 3/.style={level distance=15mm,sibling distance=17mm},
level 4/.style={level distance=18mm,sibling distance=10mm},
every circle node/.style={solid,minimum size=1.5mm,inner sep=0mm}]

% The Tree
\node(0)[solid node,label=above:$\mathsf{1.1}$]{}
child{node[solid node,label=above left:$\mathsf{2.1}$]{}
    child[norm]{node[cross = 5pt,label=above left:$\mathsf{1.2}$]{}
        child{node[cross = 5pt,label=above left:$\mathsf{2.3}$]{}
            child{node[solid node]{} edge from parent node[left]{$\mathsf{l}_3$}}
            child{node[solid node]{} edge from parent node[right]{$\mathsf{r}_3$}}
            edge from parent node[above left]{$\mathsf{L}_2$}
        }
        child{node[solid node]{} edge from parent node[above right]{$\mathsf{R}_2$}}
        edge from parent[dashdotted] node[above left]{$\mathsf{l}_1$}
    }
    child[norm]{node[solid node,label=above right:$\mathsf{1.3}$]{}
        child{node[solid node,label=above left:$\mathsf{2.4}$]{} 
            child{node[solid node]{} edge from parent node[left]{$\mathsf{l}_4$}}
            child[norm]{node[solid node]{} edge from parent node[right]{$\mathsf{r}_4$}}
            edge from parent node[above left]{$\mathsf{L}_3$}}
        child[norm]{node[solid node,label=above right:$\mathsf{2.5}$]{}
            child{node[solid node]{} edge from parent node[left]{$\mathsf{l}_5$}}
            child{node[solid node]{} edge from parent node[right]{$\mathsf{r}_5$}}
            edge from parent node[above right]{$\mathsf{R}_3$}}
        edge from parent node[above right]{$\mathsf{r}_1$}
    }
    edge from parent node[above left]{$\mathsf{L}_1$}
}
child{node[solid node,label=above right:$\mathsf{2.2}$]{}
    child{node[solid node,label=above left:$\mathsf{1.4}$]{}
        child{node[solid node]{} edge from parent node[above left]{$\mathsf{L}_4$}}
        child{node[solid node,label=above right:$\mathsf{2.6}$]{}
            child{node[solid node]{} edge from parent node[left]{$\mathsf{l}_6$}}
            child{node[solid node]{} edge from parent node[right]{$\mathsf{r}_6$}}
            edge from parent node[above right]{$\mathsf{R}_4$}}
        edge from parent node[above left]{$\mathsf{l}_2$}
    }
child{node[solid node]{} edge from parent node[above right]{$\mathsf{r}_2$}}
edge from parent node[above right]{$\mathsf{R}_1$}
};


\end{tikzpicture}
\end{document}

扩展形式博弈

答案1

点划线图案继承自上面的线条。只需添加[solid]到相关节点即可。一般来说,如果您在图形中使用的样式中混合了点图案,则明确为每种样式赋予其图案是有意义的。例如:solid node/.style={circle, draw=black, solid, inner sep=1.5, fill=black]。这样您就可以避免这类问题。

\documentclass[tikz,border=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning, calc}
\usetikzlibrary{shapes.misc}

% Node styles
\tikzset{
% Two node styles for game trees: solid and hollow
solid node/.style={circle,draw = black,solid, inner sep=1.5,fill=black},
cross/.style={cross out, draw=black, solid, ultra thick, minimum size=2*(#1-\pgflinewidth), inner sep=1.5, outer sep=0pt},
emph/.style={edge from parent/.style={solid, directed,ultra thick,draw}},
norm/.style={edge from parent/.style={solid, black,thin,draw}},
dashdot/.style={edge from parent/.style={dashdotted,thin,draw}}
}

\begin{document}

\begin{tikzpicture}[thin,
level 1/.style={level distance=15mm,sibling distance=55mm},
level 2/.style={level distance=15mm,sibling distance=27mm},
level 3/.style={level distance=15mm,sibling distance=17mm},
level 4/.style={level distance=18mm,sibling distance=10mm},
every circle node/.style={solid,minimum size=1.5mm,inner sep=0mm}]

% The Tree
\node(0)[solid node,label=above:$\mathsf{1.1}$]{}
child{node[solid node,label=above left:$\mathsf{2.1}$]{}
    child[norm]{node[cross = 5pt,label=above left:$\mathsf{1.2}$]{}
        child{node[solid,cross = 5pt,label=above left:$\mathsf{2.3}$]{}
            child{node[solid node]{} edge from parent node[left]{$\mathsf{l}_3$}}
            child{node[solid node]{} edge from parent node[right]{$\mathsf{r}_3$}}
            edge from parent node[above left]{$\mathsf{L}_2$}
        }
        child{node[solid node]{} edge from parent node[above right]{$\mathsf{R}_2$}}
        edge from parent[dashdotted] node[above left]{$\mathsf{l}_1$}
    }
    child[norm]{node[solid node,label=above right:$\mathsf{1.3}$]{}
        child{node[solid node,label=above left:$\mathsf{2.4}$]{} 
            child{node[solid node]{} edge from parent node[left]{$\mathsf{l}_4$}}
            child[norm]{node[solid node]{} edge from parent node[right]{$\mathsf{r}_4$}}
            edge from parent node[above left]{$\mathsf{L}_3$}}
        child[norm]{node[solid node,label=above right:$\mathsf{2.5}$]{}
            child{node[solid node]{} edge from parent node[left]{$\mathsf{l}_5$}}
            child{node[solid node]{} edge from parent node[right]{$\mathsf{r}_5$}}
            edge from parent node[above right]{$\mathsf{R}_3$}}
        edge from parent node[above right]{$\mathsf{r}_1$}
    }
    edge from parent node[above left]{$\mathsf{L}_1$}
}
child{node[solid node,label=above right:$\mathsf{2.2}$]{}
    child{node[solid node,label=above left:$\mathsf{1.4}$]{}
        child{node[solid node]{} edge from parent node[above left]{$\mathsf{L}_4$}}
        child{node[solid node,label=above right:$\mathsf{2.6}$]{}
            child{node[solid node]{} edge from parent node[left]{$\mathsf{l}_6$}}
            child{node[solid node]{} edge from parent node[right]{$\mathsf{r}_6$}}
            edge from parent node[above right]{$\mathsf{R}_4$}}
        edge from parent node[above left]{$\mathsf{l}_2$}
    }
child{node[solid node]{} edge from parent node[above right]{$\mathsf{r}_2$}}
edge from parent node[above right]{$\mathsf{R}_1$}
};


\end{tikzpicture}
\end{document}

答案2

这是使用istgame包,通过它你可以像使用istgame环境一样使用环境tikzpicture。你可以使用 定义交叉节点\tikzset,并将其用作宏的选项\istroot

在此处输入图片描述

\documentclass{standalone}

\usepackage{istgame}

\begin{document}    
\begin{istgame}[font=\footnotesize]
\tikzset{cross node/.style={cross out,ultra thick,inner sep=2pt}}
\xtdistance{15mm}{55mm}
\istroot(1a){1.1}
  \istb{L_1}[al]
  \istb{R_1}[ar]
  \endist
\xtdistance{15mm}{27mm}
\istroot(2a)(1a-1)<135>{2.1}
  \istb[dashdotted]{l_1}[l]
  \istb{r_1}[r]
  \endist
\istroot(2b)(1a-2)<45>{2.2}
  \istb{l_2}[l]
  \istb*{r_1}[r]
  \endist
\xtdistance{15mm}{17mm}
\istroot(1b)(2a-1)[cross node]<135>{1.2}
  \istb[dashdotted]{L_2}[l]
  \istb*[dashdotted]{R_2}[r]
  \endist
\istroot(1c)(2a-2)<45>{1.3}
  \istb{L_3}[l]
  \istb{R_3}[r]
  \endist
\istroot(1d)(2b-1)<135>{1.4}
  \istb*{L_4}[l]
  \istb{R_4}[r]
  \endist
\xtShowEndPoints
\xtdistance{18mm}{10mm}
\istroot(2c)(1b-1)[cross node]<135>{2.3}
  \istb[dashdotted]{l_3}[l]
  \istb[dashdotted]{r_3}[r]
  \endist
\istroot(2d)(1c-1)<135>{2.4}
  \istb{l_4}[l]
  \istb{r_4}[r]
  \endist
\istroot(2e)(1c-2)<45>{2.5}
  \istb{l_5}[l]
  \istb{r_5}[r]
  \endist
\istroot(2f)(1d-2)<45>{2.6}
  \istb{l_6}[l]
  \istb{r_6}[r]
  \endist
\end{istgame}

\end{document}

相关内容