答案1
这是我的尝试:
\documentclass[border=0.2cm]{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning}
\begin{document}
\begin{tikzpicture}[thick, node distance=3cm,on grid,
Rec/.style = {
draw,
minimum size = 1cm,
outer sep=0},
Circ/.style= {
draw,
circle,
minimum size=1cm}]
% Rectangles and circle
\node[Rec,fill=gray] (rec1) {};
\node[Rec,right=of rec1] (rec2) {};
\node[Circ,right=of rec2] (circle) {};
\node[Rec,above right=2cm and 3cm of circle] (rec3) {};
\node[Rec,below right=2cm and 3cm of circle] (rec4) {};
% Directed lines
\draw[-latex] (rec1) -- (rec2) edge node[above left](Nbuy){Buy}(circle);
\draw[-latex] (circle) |- (rec3) node[pos=0.71,above]{Match}node[pos=0.71,below]{$m$} (circle) |- (rec4) node[pos=0.71,below]{Mismatch}node[pos=0.71,above]{$1-m$} ;
\draw (rec3) |- ++(2,1) node[pos=0.71,above]{Keep} node[right]{$v-P$} (rec3) |- ++(2,-1)node[pos=0.75,below]{Return} node[right]{$v-h$};
\draw (rec4) |- ++(2,1) node[pos=0.71,above]{Keep} node[right]{$s-P$}(rec4) |- ++(2,-1)node[pos=0.75,below]{Return} node[right]{$-h$};
\draw (rec2) |- ++(8,-4) coordinate(Nnbuy)node[right]{$0$} ;
\node[above] at (Nbuy|-Nnbuy) {Don't buy} ;
\node[below right,align=left,inner xsep=0,inner ysep=5pt]at (rec1.south west){Retailer \\ announces \\ $P$ and $T$};
% Red dashed lines
\draw[dashed,red] (2,4) -- (2,-5)(5,4) -- (5,-5)(10.75,4) -- (10.75,-5);
% Top and bottom labels
\node at (0.75,-4.75){\textbf{Retailer}};
\node at (3.5,-4.75){\textbf{Consumer}};
\node at (7.875,-4.75){\textbf{Consumer}};
\node at (0.75,3.75){\textbf{Stage I}};
\node at (3.5,3.75){\textbf{Stage II}};
\node at (7.875,3.75){\textbf{Stage III}};
\node at (11.5,3.75){\textbf{Utility}};
\end{tikzpicture}
\end{document}
您可以检查一下关于绘制框图的教程。
答案2
使用节点的解决方案child
。
\documentclass[tikz,border=3.14159cm]{standalone}
\usetikzlibrary{arrows.meta,positioning}
\begin{document}
\begin{tikzpicture}
[grow=right, scale=1.,font=\normalsize,
edge from parent path={(\tikzparentnode) |- (\tikzchildnode.west)},
edge from parent/.style={draw,-{Stealth[scale=2]}},
level distance=3cm,
sibling distance=3cm,
level 4/.style={sibling distance=1.5cm},
auto,transform shape,
on grid]
\tikzset{every node/.style={rectangle,minimum width=1cm,minimum height=1cm,draw}}
\tikzset{edgenode/.style={draw=none,minimum height=0pt,rectangle,inner sep=3pt,pos=.75}}
\tikzset{legend/.style={draw=none,minimum height=0pt,rectangle,inner sep=3pt}}
\node[fill=gray](retailer) {}
child { node (consumer){}
child { node[circle,fill=white] { }
child { node {}
child { node[draw=none] {$-h$}
edge from parent node[edgenode,below] {Return}}
child { node[draw=none] {$s-P$}
edge from parent node[edgenode,above] {Keep}}
edge from parent node[edgenode,below] {Mismatch} node[edgenode,above] {$1-m$}}
child { node {}
child { node[draw=none] {$\nu c-h$}
edge from parent node[edgenode,below] {Return}}
child { node[draw=none] {$\nu-P$}
edge from parent node[edgenode,above] {Keep}}
edge from parent node[edgenode,above] {Match} node[edgenode,below] {$m$}}
edge from parent node[edgenode,above] {Buy}}
};
\draw[edge from parent] (consumer) --++ (0,-4) --++ (8.5,0) node[edgenode,pos=.12,above] {Don't buy} node[anchor=west,draw=none,at end] {0};
\draw[dashed] (2,4) --++ (0,-9)
(5,4) --++ (0,-9)
(11,4) --++ (0,-9);
\node[legend] at (0,-4.5) {Retailer};
\node[legend] at (3.5,-4.5) {Consumer};
\node[legend] at (8,-4.5) {Consumer};
\node[legend] at (0,3.5) {Stage I};
\node[legend] at (3.5,3.5) {Stage II};
\node[legend] at (8,3.5) {Stage III};
\node[legend] at (12,3.5) {Utility};
\node[legend,text width=2cm,align=center] at (0,-1.3) {Retailer announces P and T};
\end{tikzpicture}
\end{document}
编辑 我编辑了我的帖子,但没有删除第一个版本。这是一个改进的版本,没有第一个快速脚本的缺陷。
\documentclass[tikz,border=3.14159mm]{standalone}
\usetikzlibrary{arrows.meta,positioning}
\begin{document}
\begin{tikzpicture}
[line width=.5pt,
grow=right, scale=1.,font=\normalsize,
edge from parent path={(\tikzparentnode) |- (\tikzchildnode.west)},
edge from parent/.style={draw,-{Stealth[scale=1.5]}},
level distance=3cm,
sibling distance=3cm,
level 4/.style={sibling distance=1.5cm},
auto,transform shape,
on grid]
\tikzset{every node/.style={rectangle,minimum width=1cm,minimum height=1cm,draw}}
\tikzset{edgenode/.style={draw=none,minimum height=0pt,rectangle,inner sep=3pt,pos=.75}}
\tikzset{legend/.style={draw=none,minimum height=0pt,rectangle,inner sep=3pt}}
\node[fill=gray](retailer) {}
child { node (consumer){}
%
child { node[circle] { }
%
child { node {}
%
child { node[draw=none] {$-h$}
edge from parent[-] node[edgenode,below] {Return}}
%
child { node[draw=none] {$s-P$}
edge from parent[-] node[edgenode,above] {Keep}}
%
edge from parent node[edgenode,below] {Mismatch} node[edgenode,above] {$1-m$}}
child { node {}
%
child { node[draw=none] {$\nu c-h$}
edge from parent[-] node[edgenode,below] {Return}}
%
child { node[draw=none] {$\nu-P$}
edge from parent[-] node[edgenode,above] {Keep}}
%
edge from parent node[edgenode,above] {Match} node[edgenode,below] {$m$}} %
edge from parent node[edgenode,above] {Buy}}
};
\draw (consumer) |- (11.5,-4) node[edgenode,pos=.56,above] {Don't buy} node[anchor=west,draw=none,at end] {0};
\draw[dashed] (2,4) --++ (0,-9)
(5,4) --++ (0,-9)
(11,4) --++ (0,-9);
\node[legend] at (0,-4.5) {Retailer};
\node[legend] at (3.5,-4.5) {Consumer};
\node[legend] at (8,-4.5) {Consumer};
\node[legend] at (0,3.5) {Stage I};
\node[legend] at (3.5,3.5) {Stage II};
\node[legend] at (8,3.5) {Stage III};
\node[legend] at (12,3.5) {Utility};
\node[below = 1.2cm of retailer,legend,text width=2cm,align=center] {Retailer announces P and T};
\end{tikzpicture}
\end{document}
答案3
这是我尝试使用istgame
包裹。
\documentclass[tikz]{standalone}
\usepackage{istgame}
\usepackage{makecell}
\begin{document}
\begin{istgame}[edge from parent path={(\tikzparentnode) |- (\tikzchildnode.west)}]
\setistgrowdirection'{east}
\setistmathTF001
\setxtarrowtips{latex}[very thick]
\setistNewNodeStyle{init}[rectangle,fill=gray]{1cm}
\setistNewNodeStyle{rect}[rectangle]{1cm}
\setistNewNodeStyle{circ}{1cm}
\tikzset{RR/.style={edge from parent path={(\tikzparentnode.east)--(\tikzchildnode.west)}}} % (added)
\xtdistance{25mm}{30mm}
\istroot(0)[init]<[xshift=3mm]-90>{\makecell[l]{Retailer\\announces\\$P$ and $T$}}
\istb<RR>[->-=.75]
\endist
\istrooto(1)(0-1)[rect]
\istb<grow=0,RR>[->-=.75]{Buy}[above,pos=.3]
\istb<sibling distance=60mm,level distance=65mm>{Don't buy}[above,pos=.57]{0}
\endist
\xtdistance{25mm}{30mm}
\istrooto(2)(1-1)[circ]
\istB[->-=.93]{Match}[above,pos=.72]{$m$}[below,pos=.72]
\istB[->-=.93]{Mismatch}[below,pos=.72]{$1-m$}[above,pos=.72]
\endist
\xtdistance{15mm}{15mm}
\istrooto(3a)(2-1)[rect]
\istb{Keep}[above,pos=.75]{v-P}
\istb{Return}[below,pos=.75]{vc-h}
\endist
\istrooto(3b)(2-2)[rect]
\istb{Keep}[above,pos=.75]{s-P}
\istb{Return}[below,pos=.75]{-h}
\endist
\xtTimeLineV[dashed]([xshift=-7mm]1){3.5}{-4}{Stage I}[left=5mm]
\xtTimeLineV[dashed]([xshift=-7mm]2){3.5}{-4}{Stage II}[left=5mm]
\xtTimeLineV[dashed]([xshift=-1.5mm]3a-1){3.5}{-4}{Stage III}[left=15mm]
\xtTimeLineV[draw=none]([xshift=-1.5mm]3a-1){3.5}{-4}{\underline{Utility}}[right=2mm]
\xtTimeLineV'[draw=none]([xshift=-7mm]1){3.5}{-4}{Retailer}[left=5mm]
\xtTimeLineV'[draw=none]([xshift=-7mm]2){3.5}{-4}{Consumer}[left=5mm]
\xtTimeLineV'[draw=none]([xshift=-1.5mm]3a-1){3.5}{-4}{Consumer}[left=15mm]
\end{istgame}
\end{document}