树枝之间的间距

树枝之间的间距

我在以下树中的分支之间的间距方面遇到了问题:

\documentclass[11pt]{article}
\usepackage{tikz} %vector art
\usetikzlibrary{snakes, matrix,shapes,arrows,positioning,chains}
\begin{document}

\tikzset{
% Two node styles for game trees: solid and hollow
solid node/.style={circle,draw,inner sep=1.5,fill=black},
hollow node/.style={circle,draw,inner sep=1.5,fill=white}
}

\begin{center}
\begin{tikzpicture}[
 scale=1.5,font=\footnotesize,
 level 1/.style={level distance=10mm,sibling distance=30mm},
 level 2/.style={level distance=15mm,sibling distance=10mm},
 level 3/.style={level distance=15mm,sibling distance=10mm}
]
% The Tree
\node(0)[solid node,label=above:{\textbf{Start}}]{} 
child{node(1)[hollow node]{$L$}
child{[black] node(11)[hollow node]{}}
child{[black] node(12)[hollow node]{}}
edge from parent node[left]{$p$}
}
child{node(2)[hollow node]{$H$}
child{[black] node(41)[hollow node, ]{}}
child{[black] node(42)[hollow node,]{}}
edge from parent node[right]{$1-p$}
};
% information set
\draw[dashed,bend right](11)to(12);
\draw[dashed,bend right](41)to(42);


\path (11) -- node (H) {$x_{1}$} (12);
\path (41) -- node {$y_{1}$} (42);


% scope env to locally redefine level 1 style
%\begin{scope}[
%  level 1/.style={sibling distance=10mm}
%]
\node(00)[below=4mm,hollow node] at (H) {$H$}
child{ node[hollow node] {}
          edge from parent node[left] {$A$}
}
child{ node[solid node, label=right:{\textbf{Start 2}}] {} 
child{node(3)[hollow node]{$L$}
child{[black] node(66)[hollow node, ]{}}
child{[black] node(77)[hollow node, ]{}}
edge from parent node[left]{$p$}
}
child{node(5)[hollow node]{$H$}
child{[black] node(6)[hollow node, ]{}}
child{[black] node(7)[hollow node, ]{}}
edge from parent node[right]{$1-p$}
}
edge from parent node[right] {$R$}
}
;
%New info set
\draw[dashed,bend right](6)to(7);
\draw[dashed,bend right](66)to(77);
\path (6) -- node (HH){$r_{2}$} (7);
\path (66) -- node (HL){$z_{2}$} (77);
\node(000)[below=4mm,hollow node] at (HH) {$L$}
child{ node[hollow node, label=below:{$\{U_{i}(c_{i1},c_{i2},0,g_{2})\}_{i=H,L}$}] {} 
          edge from parent node[left] {$A$}
}
child{ node[hollow node, label=below:{$\{U_{i}(c_{i1},c_{i1},0,0)\}_{i=H,L}$}] {} 
edge from parent node[right] {$R$}
}
;
\node(0000)[below=4mm,hollow node] at (HL) {$H$}
child{ node[hollow node, label=below:{$\{U_{i}(c_{i1},c_{i2},0,g_{2})\}_{i=H,L}$}] {} 
          edge from parent node[left] {$A$}
}
child{ node[hollow node, label=below:{$\{U_{i}(c_{i1},c_{i1},0,0)\}_{i=H,L}$}] {} 
edge from parent node[right] {$R$}
}
;
%\end{scope}
\end{tikzpicture}
\end{center}
\end{document}

我曾尝试使用范围,以便可以明确定义本地环境,并且解决了间距问题,但代价是无法按照我想要的方式构建子节点: 在此处输入图片描述

有谁知道该如何“修复”我在树上遇到的间距问题吗?谢谢。

答案1

我会推荐一个更专业的树绘制包来完成这个任务。forest或者istgame可能是最合适的。

要手动执行此操作,您可以为从 Start 2 分支的 L 和 H 节点添加明确的兄弟距离:

\documentclass[11pt]{article}
\usepackage{tikz} %vector art
\usetikzlibrary{snakes, matrix,shapes,arrows,positioning,chains}
\begin{document}

\tikzset{
% Two node styles for game trees: solid and hollow
solid node/.style={circle,draw,inner sep=1.5,fill=black},
hollow node/.style={circle,draw,inner sep=1.5,fill=white}
}

\begin{center}
\begin{tikzpicture}[
 scale=1.5,font=\footnotesize,
 level 1/.style={level distance=10mm,sibling distance=30mm},
 level 2/.style={level distance=15mm,sibling distance=10mm},
 level 3/.style={level distance=15mm,sibling distance=10mm}
]
% The Tree
\node(0)[solid node,label=above:{\textbf{Start}}]{} 
child{node(1)[hollow node]{$L$}
child{[black] node(11)[hollow node]{}}
child{[black] node(12)[hollow node]{}}
edge from parent node[left]{$p$}
}
child{node(2)[hollow node]{$H$}
child{[black] node(41)[hollow node, ]{}}
child{[black] node(42)[hollow node,]{}}
edge from parent node[right]{$1-p$}
};
% information set
\draw[dashed,bend right](11)to(12);
\draw[dashed,bend right](41)to(42);


\path (11) -- node (H) {$x_{1}$} (12);
\path (41) -- node {$y_{1}$} (42);


% scope env to locally redefine level 1 style
%\begin{scope}[
%  level 1/.style={sibling distance=10mm}
%]
\node(00)[below=4mm,hollow node] at (H) {$H$}
child{ node[hollow node] {}
          edge from parent node[left] {$A$}
}
child{ node[solid node, label=right:{\textbf{Start 2}}] {} 
child[sibling distance=2.25in]{node(3)[hollow node]{$L$}
child{[black] node(66)[hollow node, ]{}}
child{[black] node(77)[hollow node, ]{}}
edge from parent node[left]{$p$}
}
child[sibling distance=2.25in]{node(5)[hollow node]{$H$}
child{[black] node(6)[hollow node, ]{}}
child{[black] node(7)[hollow node, ]{}}
edge from parent node[right]{$1-p$}
}
edge from parent node[right] {$R$}
}
;
%New info set
\draw[dashed,bend right](6)to(7);
\draw[dashed,bend right](66)to(77);
\path (6) -- node (HH){$r_{2}$} (7);
\path (66) -- node (HL){$z_{2}$} (77);
\node(000)[below=4mm,hollow node] at (HH) {$L$}
child{ node[hollow node, label=below:{$\{U_{i}(c_{i1},c_{i2},0,g_{2})\}_{i=H,L}$}] {} 
          edge from parent node[left] {$A$}
}
child{ node[hollow node, label=below:{$\{U_{i}(c_{i1},c_{i1},0,0)\}_{i=H,L}$}] {} 
edge from parent node[right] {$R$}
}
;
\node(0000)[below=4mm,hollow node] at (HL) {$H$}
child{ node[hollow node, label=below:{$\{U_{i}(c_{i1},c_{i2},0,g_{2})\}_{i=H,L}$}] {} 
          edge from parent node[left] {$A$}
}
child{ node[hollow node, label=below:{$\{U_{i}(c_{i1},c_{i1},0,0)\}_{i=H,L}$}] {} 
edge from parent node[right] {$ROO$}
}
;
%\end{scope}
\end{tikzpicture}
\end{center}
\end{document}

代码输出

答案2

这是一个解决方案,使用istgame包。您可以使用此包\xtdistance{<lev dist>}{<sib dist>}来更改级别和兄弟距离。

在此处输入图片描述

\documentclass{standalone}

\usepackage{istgame}

\begin{document}   

\begin{istgame}[scale=1.5,font=\footnotesize]
\tikzset{oval node/.style={ellipse node,minimum size=1pt,inner sep=1pt}}
\xtShowEndPoints[oval node]
% The Tree
\xtdistance{10mm}{30mm}
\istroot(S)
  \istb{p}[al]  \istb{1-p}[ar]  \endist
\xtOwner(S){\textbf{Start}} % owner
\xtdistance{15mm}{10mm}
\istrooto(L)(S-1){L}
  \istb  \istb  \endist
\istrooto(H)(S-2){H}
  \istb  \istb  \endist
\xtInfoset[bend right,dashed](L-1)(L-2){$x_1$}[centered]
\xtInfoset[bend right,dashed](H-1)(H-2){$y_1$}[centered]
\xtdistance{10mm}{25mm}
\istrooto(00)([yshift=-18mm]L){H}
  \istb{A}[l]  \istb{R}[r]  \endist
% The Tree: Start 2
\xtdistance{10mm}{50mm}
\istroot(S2)(00-2)
  \istb{p}[al]  \istb{1-p}[ar]  \endist
\xtOwner(S2){\textbf{\ Start 2}}[right]
\xtdistance{15mm}{10mm}
\istrooto(L2)(S2-1){L}
  \istb  \istb  \endist
\istrooto(H2)(S2-2){H}
  \istb  \istb  \endist
\xtInfoset[bend right,dashed](L2-1)(L2-2){$z_2$}[centered]
\xtInfoset[bend right,dashed](H2-1)(H2-2){$r_2$}[centered]
\xtdistance{10mm}{25mm}
\istrooto(HH)([yshift=-18mm]L2){H}
  \istb{A}[l]{\{U_{i}(c_{i1},c_{i2},0,g_{2})\}_{i=H,L}}
  \istb{ROO}[r]{\{U_{i}(c_{i1},c_{i1},0,0)\}_{i=H,L}}
  \endist
\istrooto(LL)([yshift=-18mm]H2){L}
  \istb{A}[l]{\{U_{i}(c_{i1},c_{i2},0,g_{2})\}_{i=H,L}}
  \istb{R}[r]{\{U_{i}(c_{i1},c_{i1},0,0)\}_{i=H,L}}
  \endist
\end{istgame}
\end{document}

相关内容