我正在尝试添加两个标签,分别位于两条虚线上。每次我在创建线条的位置添加一些代码变体时,相应的标签都会显示在图的顶部。我遗漏了什么?
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning}
\begin{document}
\begin{figure}
\begin{center}
\small
\begin{tikzpicture}[thin,
level 1/.style={sibling distance=60mm},
level 2/.style={sibling distance=25mm},
level 3/.style={sibling distance=15mm},
every circle node/.style={minimum size=1.5mm,inner sep=1.25mm}]
\node[circle,draw,label=above:$N$] (root) {}
child { node [circle,draw,label=above:$1$] {}
child {
node[circle,draw,label=below:$A$] (node-A) {}
child {
node {$8,3$}
edge from parent
node[left] {$S$}}
child {
node {$6,5$}
edge from parent
node[right] {$\neg S$}}
edge from parent
node[left] {$C$}}
child {
node[circle,draw,label=below:$A$] (node-B) {}
child {
node {$5,8$}
edge from parent
node[left] {$S$}}
child {
node {$2,7$}
edge from parent
node[right] {$\neg S$}}
edge from parent
node[right] {$\neg C$}}
edge from parent
node[left] {$Type I$}}
child { node [circle,draw,label=above:$2$] {}
child {
node[circle,draw,label=below:$A$] (node-C) {}
child {
node {$7,6$}
edge from parent
node[left] {$S$}}
child {
node {$3,4$}
edge from parent
node[right] {$\neg S$}}
edge from parent
node[left] {$C$}}
child {
node[circle,draw,label=below:$A$] (node-D) {}
child {
node {$1,0$}
edge from parent
node[left] {$S$}}
child {
node {$0,1$}
edge from parent
node[right] {$\neg S$}}
edge from parent
node[right] {$\neg C$}}
edge from parent
node[right] {$Type II$}};
\draw [dashed,out=45,in=135] (node-A) to (node-C)
[dashed,out=45,in=135] (node-B) to (node-D);
\end{tikzpicture}
\end{center}
\caption{Extensive-form game}
\end{figure}
\end{document}
答案1
只是因为它是一棵树......
一旦在树的序言中设置了配置,森林就可以非常简洁、干净地指定树。
请注意,这需要 Forest 版本 2.1:
\documentclass[border=10pt,tikz]{standalone}
\usepackage{forest}
\usetikzlibrary{quotes}
\begin{document}
\begin{forest}
/tikz/every edge quotes/.style={midway, above},
my edge label/.style n args=3{
% if={>On={n}{1}}{edge label={node [midway, left, #1] {#2}}}{edge label={node [midway, right, #1] {#3}}}
% Sašo: http://chat.stackexchange.com/transcript/message/34010033#34010033
edge label/.process={On=?}{n}{1}{node [midway, left, #1] {#2}}{node [midway, right, #1] {#3}}
},
my inverse edge label/.style={
my edge label={}{$#1$}{$\lnot #1$}
},
my arc label/.style n args=2{
tikz+={
\draw [dashed, out=135, in=45] () edge ["#1"] (#2);
}
},
for tree={math content, l sep*=3, s sep*=3},
before typesetting nodes={
where n children=0{% terminal nodes
my inverse edge label=S
}{% non-terminal nodes
if level=2{
label/.wrap pgfmath arg={below:$#1$}{content()},
my inverse edge label=C
}{
label/.wrap pgfmath arg={above:$#1$}{content()},
my edge label={font=\itshape}{Type I}{Type II}
},
content=,
draw,
circle,
inner sep=1.25mm,
}
},
[N
[1
[A
[{8,3}]
[{6,5}]
]
[A
[{5,8}]
[{2,7}]
]
]
[2
[A, my arc label={label here}{!r11}
[{7,6}]
[{3,4}]
]
[A, my arc label={label there}{!r12}
[{1,0}]
[{0,1}]
]
]
]
\end{forest}
\end{document}
答案2
您只需向虚线曲线添加一个节点即可:)。例如:
\draw[dashed,out=45,in=135] (node-A) to node[above] {label left} (node-C)
(node-B) to node[above] {label right} (node-D);
或者使用 Tikz 库quotes
:
\draw[dashed,out=45,in=135] (node-A) to ["label left"](node-C)
(node-B) to ["label right"](node-D);
第二种情况的完整 MWE 为:
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning, quotes}% <-- changed
\begin{document}
\begin{figure}
\centering
\begin{tikzpicture}[thin,
level 1/.style={sibling distance=60mm},
level 2/.style={sibling distance=25mm},
level 3/.style={sibling distance=15mm},
every circle node/.style={minimum size=1.5mm,inner sep=1.25mm},
font = \small
]
\node[circle,draw,label=above:$N$] (root) {}
child { node [circle,draw,label=above:$1$] {}
child {
node[circle,draw,label=below:$A$] (node-A) {}
child {
node {$8,3$}
edge from parent
node[left] {$S$}}
child {
node {$6,5$}
edge from parent
node[right] {$\neg S$}}
edge from parent
node[left] {$C$}}
child {
node[circle,draw,label=below:$A$] (node-B) {}
child {
node {$5,8$}
edge from parent
node[left] {$S$}}
child {
node {$2,7$}
edge from parent
node[right] {$\neg S$}}
edge from parent
node[right] {$\neg C$}}
edge from parent
node[left] {$Type I$}}
child { node [circle,draw,label=above:$2$] {}
child {
node[circle,draw,label=below:$A$] (node-C) {}
child {
node {$7,6$}
edge from parent
node[left] {$S$}}
child {
node {$3,4$}
edge from parent
node[right] {$\neg S$}}
edge from parent
node[left] {$C$}}
child {
node[circle,draw,label=below:$A$] (node-D) {}
child {
node {$1,0$}
edge from parent
node[left] {$S$}}
child {
node {$0,1$}
edge from parent
node[right] {$\neg S$}}
edge from parent
node[right] {$\neg C$}}
edge from parent
node[right] {$Type II$}};
\draw[dashed,out=45,in=135] (node-A) to ["label left"] (node-C) % <-- changed
(node-B) to ["label right"] (node-D);% <-- changed
\end{tikzpicture}
\caption{Extensive-form game}
\end{figure}
\end{document}
答案3
编辑:istgame
v2.0
这istgame
提供一个新的宏\xtCinfoset
来绘制弯曲的(甚至倾斜的)信息集。
\documentclass{standalone}
\usepackage{istgame}
\begin{document}
\begin{istgame}[font=\small]
\tikzset{decision node/.style={ellipse node,inner sep=3.5pt}}
\setistmathTF*101 % action labels in italics
\xtdistance{15mm}{60mm}
\istroot(0){N}
\istb{Type I}[al] \istb{Type II}[ar] \endist
\setistmathTF111 % all important labels are in math mode
\xtdistance{15mm}{25mm}
\istroot(1)(0-1){1}
\istb{C}[al] \istb{\neg C}[ar] \endist
\istroot(2)(0-2){2}
\istb{C}[al] \istb{\neg C}[ar] \endist
\xtdistance{15mm}{15mm}
\istroot(11)(1-1)<-90>{A}
\istb{S}[l]{8,3} \istb{\neg S}[r]{6,5} \endist
\istroot(12)(1-2)<-90>{A}
\istb{S}[l]{5,8} \istb{\neg S}[r]{2,7} \endist
\istroot(21)(2-1)<-90>{A}
\istb{S}[l]{7,6} \istb{\neg S}[r]{3,4} \endist
\istroot(22)(2-2)<-90>{A}
\istb{S}[l]{1,0} \istb{\neg S}[r]{0,1} \endist
% curved information set
\xtCInfoset(11)(21)<1.4>{label here}
% skewed curved information set
\xtCInfoset(12)!.75!(22)<1.8>{label there}
\end{istgame}
\end{document}
原始答案
要绘制信息集,您可以\xtInfoset
使用istgame
包裹:
\documentclass{standalone}
\usepackage{istgame}
\begin{document}
\begin{istgame}[font=\small]
\tikzset{decision node/.style={ellipse node,inner sep=3.5pt}}
\xtdistance{15mm}{60mm}
\istroot(0){$N$}
\istb{Type I}[al]
\istb{Type II}[ar]
\endist
\xtdistance{15mm}{25mm}
\istroot(1)(0-1){1}
\istb{C}[al]
\istb{\neg C}[ar]
\endist
\istroot(2)(0-2){2}
\istb{C}[al]
\istb{\neg C}[ar]
\endist
\xtdistance{15mm}{15mm}
\istroot(11)(1-1)<-90>{A}
\istb{S}[l]{8,3}
\istb{\neg S}[r]{6,5}
\endist
\istroot(12)(1-2)<-90>{A}
\istb{S}[l]{5,8}
\istb{\neg S}[r]{2,7}
\endist
\istroot(21)(2-1)<-90>{A}
\istb{S}[l]{7,6}
\istb{\neg S}[r]{3,4}
\endist
\istroot(22)(2-2)<-90>{A}
\istb{S}[l]{1,0}
\istb{\neg S}[r]{0,1}
\endist
\xtInfoset[thin,dashed,bend left=45](11)(21){label here}[yshift=37pt]
\xtInfoset[thin,dashed,bend left=45](12)(22){label there}[yshift=35pt]
\end{istgame}
\end{document}