Small corrections needed for game tree
I've drawn what I would like the result to be:
The current game tree looks like this:
With the current code:
documentclass[12pt,twoside]{book}%{book}
usepackage[a4paper, hmargin={2.5cm, 2.5cm}, vmargin={2.5cm, 2.5cm},bindingoffset=6mm]{geometry}
usepackage{tikz}
usetikzlibrary{calc}
usepackage[dvipsnames]{xcolor}
usetikzlibrary{fit}% <-- new
begin{document}
begin{figure}
begin{tikzpicture}[
font = footnotesize,
edge from parent/.style = {draw ,thin},
SN/.style = {%solid node
circle, inner sep=1.2 ,fill=blue},
HN/.style = {%hollow node
circle, inner sep=1.2, draw=blue,
},
level distance = 25mm,
level 1/.style = {sibling distance=50mm},
level 2/.style = {sibling distance=40mm}
]
%---
linespread{0.8}
%-------
node (n0) [HN] {}
child{ node (n1) [SN] {}
edge from parent node[left]{$n_c$ buy}
}
child{ node (n2) [SN] {}
child{node[HN] {}
edge from parent node[left]{$1-n_c$ buy}}
child{node[HN] {}
edge from parent node[right]{not buy}}
edge from parent node[right]{not buy}
};
draw[<-,shorten <=1pt]
(n0) -- + (2,1) node[right,align=left] {Entrepreneur\
sets $P_c$ };
draw[<-,shorten <=1pt]
(n2) -- + (2,1) node[right,align=left] {Entrepreneur\
sets $P_r$ };
end{tikzpicture}
caption{Timing of game}
label{Testing label}
floatfoot{textit{Source}: Own illustration}
end{figure}
end{tikzpicture}
end{document}
I don't know how to add the timelines -----t=0,1,2 on each stage and how to implement the profit and utility functions after each node. Guidance much appreciated :)
tikz-pgf tikz-styles
add a comment |
I've drawn what I would like the result to be:
The current game tree looks like this:
With the current code:
documentclass[12pt,twoside]{book}%{book}
usepackage[a4paper, hmargin={2.5cm, 2.5cm}, vmargin={2.5cm, 2.5cm},bindingoffset=6mm]{geometry}
usepackage{tikz}
usetikzlibrary{calc}
usepackage[dvipsnames]{xcolor}
usetikzlibrary{fit}% <-- new
begin{document}
begin{figure}
begin{tikzpicture}[
font = footnotesize,
edge from parent/.style = {draw ,thin},
SN/.style = {%solid node
circle, inner sep=1.2 ,fill=blue},
HN/.style = {%hollow node
circle, inner sep=1.2, draw=blue,
},
level distance = 25mm,
level 1/.style = {sibling distance=50mm},
level 2/.style = {sibling distance=40mm}
]
%---
linespread{0.8}
%-------
node (n0) [HN] {}
child{ node (n1) [SN] {}
edge from parent node[left]{$n_c$ buy}
}
child{ node (n2) [SN] {}
child{node[HN] {}
edge from parent node[left]{$1-n_c$ buy}}
child{node[HN] {}
edge from parent node[right]{not buy}}
edge from parent node[right]{not buy}
};
draw[<-,shorten <=1pt]
(n0) -- + (2,1) node[right,align=left] {Entrepreneur\
sets $P_c$ };
draw[<-,shorten <=1pt]
(n2) -- + (2,1) node[right,align=left] {Entrepreneur\
sets $P_r$ };
end{tikzpicture}
caption{Timing of game}
label{Testing label}
floatfoot{textit{Source}: Own illustration}
end{figure}
end{tikzpicture}
end{document}
I don't know how to add the timelines -----t=0,1,2 on each stage and how to implement the profit and utility functions after each node. Guidance much appreciated :)
tikz-pgf tikz-styles
Anyone that can help? :/
– Saud
May 26 '16 at 19:00
Perhaps, but it would really be appreciated if you could fix the code so that it compiles without errors.
– Torbjørn T.
May 27 '16 at 19:52
add a comment |
I've drawn what I would like the result to be:
The current game tree looks like this:
With the current code:
documentclass[12pt,twoside]{book}%{book}
usepackage[a4paper, hmargin={2.5cm, 2.5cm}, vmargin={2.5cm, 2.5cm},bindingoffset=6mm]{geometry}
usepackage{tikz}
usetikzlibrary{calc}
usepackage[dvipsnames]{xcolor}
usetikzlibrary{fit}% <-- new
begin{document}
begin{figure}
begin{tikzpicture}[
font = footnotesize,
edge from parent/.style = {draw ,thin},
SN/.style = {%solid node
circle, inner sep=1.2 ,fill=blue},
HN/.style = {%hollow node
circle, inner sep=1.2, draw=blue,
},
level distance = 25mm,
level 1/.style = {sibling distance=50mm},
level 2/.style = {sibling distance=40mm}
]
%---
linespread{0.8}
%-------
node (n0) [HN] {}
child{ node (n1) [SN] {}
edge from parent node[left]{$n_c$ buy}
}
child{ node (n2) [SN] {}
child{node[HN] {}
edge from parent node[left]{$1-n_c$ buy}}
child{node[HN] {}
edge from parent node[right]{not buy}}
edge from parent node[right]{not buy}
};
draw[<-,shorten <=1pt]
(n0) -- + (2,1) node[right,align=left] {Entrepreneur\
sets $P_c$ };
draw[<-,shorten <=1pt]
(n2) -- + (2,1) node[right,align=left] {Entrepreneur\
sets $P_r$ };
end{tikzpicture}
caption{Timing of game}
label{Testing label}
floatfoot{textit{Source}: Own illustration}
end{figure}
end{tikzpicture}
end{document}
I don't know how to add the timelines -----t=0,1,2 on each stage and how to implement the profit and utility functions after each node. Guidance much appreciated :)
tikz-pgf tikz-styles
I've drawn what I would like the result to be:
The current game tree looks like this:
With the current code:
documentclass[12pt,twoside]{book}%{book}
usepackage[a4paper, hmargin={2.5cm, 2.5cm}, vmargin={2.5cm, 2.5cm},bindingoffset=6mm]{geometry}
usepackage{tikz}
usetikzlibrary{calc}
usepackage[dvipsnames]{xcolor}
usetikzlibrary{fit}% <-- new
begin{document}
begin{figure}
begin{tikzpicture}[
font = footnotesize,
edge from parent/.style = {draw ,thin},
SN/.style = {%solid node
circle, inner sep=1.2 ,fill=blue},
HN/.style = {%hollow node
circle, inner sep=1.2, draw=blue,
},
level distance = 25mm,
level 1/.style = {sibling distance=50mm},
level 2/.style = {sibling distance=40mm}
]
%---
linespread{0.8}
%-------
node (n0) [HN] {}
child{ node (n1) [SN] {}
edge from parent node[left]{$n_c$ buy}
}
child{ node (n2) [SN] {}
child{node[HN] {}
edge from parent node[left]{$1-n_c$ buy}}
child{node[HN] {}
edge from parent node[right]{not buy}}
edge from parent node[right]{not buy}
};
draw[<-,shorten <=1pt]
(n0) -- + (2,1) node[right,align=left] {Entrepreneur\
sets $P_c$ };
draw[<-,shorten <=1pt]
(n2) -- + (2,1) node[right,align=left] {Entrepreneur\
sets $P_r$ };
end{tikzpicture}
caption{Timing of game}
label{Testing label}
floatfoot{textit{Source}: Own illustration}
end{figure}
end{tikzpicture}
end{document}
I don't know how to add the timelines -----t=0,1,2 on each stage and how to implement the profit and utility functions after each node. Guidance much appreciated :)
tikz-pgf tikz-styles
tikz-pgf tikz-styles
edited May 26 '16 at 10:28
Saud
asked May 26 '16 at 10:15
Saud Saud
33639
33639
Anyone that can help? :/
– Saud
May 26 '16 at 19:00
Perhaps, but it would really be appreciated if you could fix the code so that it compiles without errors.
– Torbjørn T.
May 27 '16 at 19:52
add a comment |
Anyone that can help? :/
– Saud
May 26 '16 at 19:00
Perhaps, but it would really be appreciated if you could fix the code so that it compiles without errors.
– Torbjørn T.
May 27 '16 at 19:52
Anyone that can help? :/
– Saud
May 26 '16 at 19:00
Anyone that can help? :/
– Saud
May 26 '16 at 19:00
Perhaps, but it would really be appreciated if you could fix the code so that it compiles without errors.
– Torbjørn T.
May 27 '16 at 19:52
Perhaps, but it would really be appreciated if you could fix the code so that it compiles without errors.
– Torbjørn T.
May 27 '16 at 19:52
add a comment |
5 Answers
5
active
oldest
votes
The missing text has been added as label
s to the nodes. I defined a style addlabel
for convenience. The amsmath
package is added for the text
macro.
For the missing lines, I use the syntax of the calc
library to draw a line relative to the n0
node, and I add a coordinate
at each end of that line (l1
and l2
). The next two lines are drawn with perpendicular coordinates, e.g. (l1 |- n2)
is the point that has the x-coordinate of l1
and the y-coordinate of n2
. This makes it easy to draw the lines of the same length.
I also removed the xcolor
package, as that is already loaded by tikz
, and moved the dvipsnames
option to the documentclass.
I don't know where floatfoot
comes from, so that is commented out, and the extra end{tikzpicture}
you had is removed. I also commented the linespread
, do you really want that? (Personally I'd remove it.)
documentclass[12pt,twoside,dvipsnames]{book}%{book}
usepackage{amsmath}
usepackage{tikz}
usetikzlibrary{calc}
begin{document}
begin{figure}
centering
begin{tikzpicture}[
font = footnotesize,
edge from parent/.style = {draw ,thin},
SN/.style = {%solid node
circle, inner sep=1.2 ,fill=blue,
},
HN/.style = {%hollow node
circle, inner sep=1.2, draw=blue,
},
addlabel/.style={label={[align=center]below:#1}},
level distance = 25mm,
level 1/.style = {sibling distance=50mm},
level 2/.style = {sibling distance=40mm}
]
%---
%linespread{0.8}
%-------
node (n0) [HN] {}
child{ node (n1) [SN,addlabel={$pi_1=text{equation 1}$\$u_1=text{utility 1}$}] {}
edge from parent node[left]{$n_c$ buy}
}
child{ node (n2) [SN] {}
child{node[HN,addlabel={$pi_2=text{equation 2}$\$u_2=text{utility 2}$}] {}
edge from parent node[left]{$1-n_c$ buy}}
child{node[HN,addlabel={0\0}] (n3) {}
edge from parent node[right]{not buy}}
edge from parent node[right]{not buy}
};
draw[<-,shorten <=1pt]
(n0) -- + (2,1) node[right,align=left] {Entrepreneur\
sets $P_c$ };
draw[<-,shorten <=1pt]
(n2) -- + (2,1) node[right,align=left] {Entrepreneur\
sets $P_r$ };
draw [dotted] ($(n0.center)+(-4cm,0)$) coordinate (l1) -- ($(n0.center) + (6cm,0)$) coordinate (l2) node[right] {$t=0$};
draw [dotted] (l1 |- n2) -- (l2 |- n2) node[right] {$t=1$};
draw [dotted] (l1 |- n3) -- (l2 |- n3) node[right] {$t=3$};
end{tikzpicture}
caption{Timing of game}
label{Testing label}
% floatfoot{textit{Source}: Own illustration}
end{figure}
end{document}
add a comment |
A solution with forest
Code
documentclass[12pt,twoside]{book}%{book}
usepackage[a4paper, hmargin={2.5cm, 2.5cm}, vmargin={2.5cm, 2.5cm},bindingoffset=6mm]{geometry}
usepackage{forest,mathtools}
forestset{
declare toks={elo}{}, % Edge Label Options
anchors/.style={anchor=#1,child anchor=#1,parent anchor=#1},
dot/.style={tikz={draw[blue,#1] (.child anchor) circle[radius=1.5pt];}},
decision edge label/.style n args=3{
edge label/.expanded={node[midway,auto=#1,anchor=#2,forestoption{elo}]{strutunexpanded{#3}}}
},
decision/.style={if n=1
{decision edge label={left}{east}{#1}}
{decision edge label={right}{west}{#1}}
},
game tree/.style={
for tree={
s sep=30mm,l=25mm,
if n children=0{anchors=north}{
if n=1{anchors=south east}{anchors=south west}},
math content,
},
anchors=south,
dot={fill=white},for descendants={dot={fill=blue}},
delay={for descendants={split option={content}{;}{decision,content}}},
},
}
newcommandpayoff[1]{begin{matrix}#1end{matrix}}
begin{document}
begin{figure}
centering
begin{forest}
game tree,
[
[$n_c$ buy;payoff{pi_1=text{equation 1} \ u_1=text{utility 1}}]
[not buy;
[$1-n_c$ buy;payoff{pi_2=text{equation 2} \ u_2=text{utility 2}},dot={fill=white}]
[not buy;payoff{0 \ 0},dot={fill=white}]
]
]
draw[<-,shorten <=3pt]
(!r.anchor) -- + (2,1) node[right,align=left] {Entrepreneur\
sets $P_c$ };
draw[<-,shorten <=3pt]
(!2.anchor) -- + (2,1) node[right,align=left] {Entrepreneur\
sets $P_r$ };
draw[dotted](current bounding box.west|-!r.anchor)--(current bounding box.east|-!r.anchor)node[right,overlay]{$t=0$};
draw[dotted](current bounding box.west|-!2.anchor)--(current bounding box.east|-!2.anchor)node[right,overlay]{$t=1$};
draw[dotted](current bounding box.west|-!21.anchor)--(current bounding box.east|-!22.anchor)node[right,overlay]{$t=2$};
end{forest}
caption{Timing of game}
label{Testing label}
% floatfoot{textit{Source}: Own illustration}
end{figure}
end{document}
Output
add a comment |
A shorter but inflexible forest
implementation:
Code
documentclass[tikz]{standalone}
usepackage{forest}usetikzlibrary{arrows.meta}
begin{document}
begin{forest}
Pin/.style={pin={[pin edge={thin,shorten <=4pgflinewidth,black,{Latex[round]}-,
to path={-- (tikztotarget.west)}}, pin distance=1.5cm, align=left]
10:Entrepreneur\ sets $P_#1$}},
buy/.style={edge label={node[inner sep=.1667em, /forest/if level=2{near end}{midway},
/forest/if n=1{above left}{above right}] {#1 buy}}},
c/.style={node options={circle,fill,outer sep=0pt,inner sep=.4mm},anchor=center},
foo/.style={anchor=parent, child anchor=parent, node options={align=left,
append after command={(.parent) edge[fill,to path={circle[radius=.4mm]}] ()}},
content={$pi_{pgfmathprint{level}} = {}$equation pgfmathprint{level}\
$u_{pgfmathprint{level}} = {}$utility pgfmathprint{level}}},
for tree={l sep=2.5cm, s sep*=5,if n=1{alias/.wrap pgfmath arg={level-#1}{level()}}{}}
[, c, Pin=c, alias=level-0
[, foo, buy=$n_c$]
[, c, buy=not, Pin=r
[, foo, buy=$1-n_c$]
[, foo, content={0\0}, buy=not] ] ]
path(current bounding box.west)coordinate(cbbw)(current bounding box.east)coordinate(cbbe);
foreach l[evaluate={a={l==0?"center":"north"};}] in {0,...,2}
draw[dashed] (cbbw |- level-l.a) -- (cbbe |- level-l.a) node[right] {$t=l$};
end{forest}
end{document}
Nice ;) Do you neednode options
forc
?
– cfr
May 28 '16 at 2:11
add a comment |
This is a demonstration using an experimental package justtrees
. (Code available on request.)
justtrees
is a forest
-based package designed to make it easy to align labels horizontally with the different levels of the tree. Labels may be aligned to the left and/or right of the tree and formatting may be configured globally. just={<label>}
adds a label, by default, to the right as shown here.
The backgrounds
library is used to ensure the dotted lines are drawn behind the tree and arrows.meta
is used for the circles which are filled with white or blue to obscure the dots. justtrees
automatically figures out where to place the labels on the right. Since the package is based on forest
, forest
's facilities are used to automate the addition of these labels, the placement and format of edge labels and the overall style of the tree.
Once configured, the tree itself is specified quite concisely with
[, pin=45:{Entrepreneur\sets $P_c$}
[{$pi_1 = text{equation 1}$\$u_1 = text{utility 1}$}, edge label={$n_c$ buy}
]
[, edge label=not buy, pin=45:{Entrepreneur\sets $P_r$}
[{$pi_2 = text{equation 2}$\$u_2 = text{utility 2}$}, edge label={$1 - n_c$ buy}
]
[$0$\$0$, edge label=not buy
]
]
]
documentclass[tikz,border=10pt,multi]{standalone}
usepackage{justtrees,amsmath}% justtrees rev 4959
usetikzlibrary{arrows.meta,backgrounds}
begin{document}
begin{justtree}
{
/tikz/every pin/.append style={pin distance=40pt, align=left},
/tikz/every pin edge/.append style={shorten <=2pt, {Stealth}-, draw=black},
delay={
where n children=0{%
label/.wrap pgfmath arg={[align=center, label distance=5pt]below:#1}{content()},
content={},
}{},
for tree={
if n=1{
edge label/.wrap value={node [midway, left, anchor=mid east] {#1}},
}{
edge label/.wrap value={node [midway, right, anchor=mid west] {#1}},
},
}
},
for tree={%
l sep'+=70pt,
s sep'+=80pt,
+edge={%
shorten >=-2pt,
shorten <=-2pt,
},
if level=3{%
+edge={%
{Circle[width=4pt,length=4pt,blue,fill=blue]}-{Circle[width=4pt,length=4pt,blue,fill=white]},
},
}{%
+edge={%
{Circle[width=4pt,length=4pt,blue,fill=white]}-{Circle[width=4pt,length=4pt,blue,fill=white]},
},
},
},
before typesetting nodes={%
for nodewalk={fake=r,L,ancestors}{%
if level=0{}{%
just/.wrap pgfmath arg={$t=#1$}{int(level()-1)},
tikz+/.wrap pgfmath arg={%
scoped[on background layer]{%
draw [densely dotted] (right just #1) -- (right just #1 -| just tree west);
}
}{level()}
}
}
},
just format={anchor=west},
}
[, pin=45:{Entrepreneur\sets $P_c$}
[{$pi_1 = text{equation 1}$\$u_1 = text{utility 1}$}, edge label={$n_c$ buy}
]
[, edge label=not buy, pin=45:{Entrepreneur\sets $P_r$}
[{$pi_2 = text{equation 2}$\$u_2 = text{utility 2}$}, edge label={$1 - n_c$ buy}
]
[$0$\$0$, edge label=not buy
]
]
]
end{justtree}
end{document}
add a comment |
The istgame
package (version 2) provides macros for time-lines: xtTimeLineH
and xtTimeLineV
. It also provides macros for comments: xtCommentTo
and xtCommentFrom
.
Here is an example of using xtTimeLineH
and xtCommentTo
.
documentclass{standalone}
usepackage{amsmath}
usepackage{makecell}
usepackage{istgame}
begin{document}
begin{istgame}[font=footnotesize]
% tree
setistmathTF001
xtShowEndPoints
xtdistance{25mm}{50mm}
istroot(0)
istb{$n_c$ buy}[al]{makecell[l]{pi_1=text{equation 1}\u_1=text{utility 1}}}
istb{not buy}[ar]
endist
istroot(1)(0-2)
istb{$1-n_c$ buy}[al]{makecell[l]{pi_2=text{equation 2}\u_2=text{utility 2}}}
istb{not buy}[ar]{makecell{0\0}}
endist
% time-lines and comments
xtTimeLineH(0){-4cm}{6cm}{$t=0$}
xtTimeLineH(1){-4cm}{6cm}{$t=1$}
xtTimeLineH(1-1){-4cm}{6cm}{$t=2$}
xtCommentTo[solid](0)(2,1){makecell[l]{Entrepreneur\sets $P_c$}}[r]
xtCommentTo[solid](1)(2,1){makecell[l]{Entrepreneur\sets $P_r$}}[r]
end{istgame}
end{document}
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "85"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f311570%2fsmall-corrections-needed-for-game-tree%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
5 Answers
5
active
oldest
votes
5 Answers
5
active
oldest
votes
active
oldest
votes
active
oldest
votes
The missing text has been added as label
s to the nodes. I defined a style addlabel
for convenience. The amsmath
package is added for the text
macro.
For the missing lines, I use the syntax of the calc
library to draw a line relative to the n0
node, and I add a coordinate
at each end of that line (l1
and l2
). The next two lines are drawn with perpendicular coordinates, e.g. (l1 |- n2)
is the point that has the x-coordinate of l1
and the y-coordinate of n2
. This makes it easy to draw the lines of the same length.
I also removed the xcolor
package, as that is already loaded by tikz
, and moved the dvipsnames
option to the documentclass.
I don't know where floatfoot
comes from, so that is commented out, and the extra end{tikzpicture}
you had is removed. I also commented the linespread
, do you really want that? (Personally I'd remove it.)
documentclass[12pt,twoside,dvipsnames]{book}%{book}
usepackage{amsmath}
usepackage{tikz}
usetikzlibrary{calc}
begin{document}
begin{figure}
centering
begin{tikzpicture}[
font = footnotesize,
edge from parent/.style = {draw ,thin},
SN/.style = {%solid node
circle, inner sep=1.2 ,fill=blue,
},
HN/.style = {%hollow node
circle, inner sep=1.2, draw=blue,
},
addlabel/.style={label={[align=center]below:#1}},
level distance = 25mm,
level 1/.style = {sibling distance=50mm},
level 2/.style = {sibling distance=40mm}
]
%---
%linespread{0.8}
%-------
node (n0) [HN] {}
child{ node (n1) [SN,addlabel={$pi_1=text{equation 1}$\$u_1=text{utility 1}$}] {}
edge from parent node[left]{$n_c$ buy}
}
child{ node (n2) [SN] {}
child{node[HN,addlabel={$pi_2=text{equation 2}$\$u_2=text{utility 2}$}] {}
edge from parent node[left]{$1-n_c$ buy}}
child{node[HN,addlabel={0\0}] (n3) {}
edge from parent node[right]{not buy}}
edge from parent node[right]{not buy}
};
draw[<-,shorten <=1pt]
(n0) -- + (2,1) node[right,align=left] {Entrepreneur\
sets $P_c$ };
draw[<-,shorten <=1pt]
(n2) -- + (2,1) node[right,align=left] {Entrepreneur\
sets $P_r$ };
draw [dotted] ($(n0.center)+(-4cm,0)$) coordinate (l1) -- ($(n0.center) + (6cm,0)$) coordinate (l2) node[right] {$t=0$};
draw [dotted] (l1 |- n2) -- (l2 |- n2) node[right] {$t=1$};
draw [dotted] (l1 |- n3) -- (l2 |- n3) node[right] {$t=3$};
end{tikzpicture}
caption{Timing of game}
label{Testing label}
% floatfoot{textit{Source}: Own illustration}
end{figure}
end{document}
add a comment |
The missing text has been added as label
s to the nodes. I defined a style addlabel
for convenience. The amsmath
package is added for the text
macro.
For the missing lines, I use the syntax of the calc
library to draw a line relative to the n0
node, and I add a coordinate
at each end of that line (l1
and l2
). The next two lines are drawn with perpendicular coordinates, e.g. (l1 |- n2)
is the point that has the x-coordinate of l1
and the y-coordinate of n2
. This makes it easy to draw the lines of the same length.
I also removed the xcolor
package, as that is already loaded by tikz
, and moved the dvipsnames
option to the documentclass.
I don't know where floatfoot
comes from, so that is commented out, and the extra end{tikzpicture}
you had is removed. I also commented the linespread
, do you really want that? (Personally I'd remove it.)
documentclass[12pt,twoside,dvipsnames]{book}%{book}
usepackage{amsmath}
usepackage{tikz}
usetikzlibrary{calc}
begin{document}
begin{figure}
centering
begin{tikzpicture}[
font = footnotesize,
edge from parent/.style = {draw ,thin},
SN/.style = {%solid node
circle, inner sep=1.2 ,fill=blue,
},
HN/.style = {%hollow node
circle, inner sep=1.2, draw=blue,
},
addlabel/.style={label={[align=center]below:#1}},
level distance = 25mm,
level 1/.style = {sibling distance=50mm},
level 2/.style = {sibling distance=40mm}
]
%---
%linespread{0.8}
%-------
node (n0) [HN] {}
child{ node (n1) [SN,addlabel={$pi_1=text{equation 1}$\$u_1=text{utility 1}$}] {}
edge from parent node[left]{$n_c$ buy}
}
child{ node (n2) [SN] {}
child{node[HN,addlabel={$pi_2=text{equation 2}$\$u_2=text{utility 2}$}] {}
edge from parent node[left]{$1-n_c$ buy}}
child{node[HN,addlabel={0\0}] (n3) {}
edge from parent node[right]{not buy}}
edge from parent node[right]{not buy}
};
draw[<-,shorten <=1pt]
(n0) -- + (2,1) node[right,align=left] {Entrepreneur\
sets $P_c$ };
draw[<-,shorten <=1pt]
(n2) -- + (2,1) node[right,align=left] {Entrepreneur\
sets $P_r$ };
draw [dotted] ($(n0.center)+(-4cm,0)$) coordinate (l1) -- ($(n0.center) + (6cm,0)$) coordinate (l2) node[right] {$t=0$};
draw [dotted] (l1 |- n2) -- (l2 |- n2) node[right] {$t=1$};
draw [dotted] (l1 |- n3) -- (l2 |- n3) node[right] {$t=3$};
end{tikzpicture}
caption{Timing of game}
label{Testing label}
% floatfoot{textit{Source}: Own illustration}
end{figure}
end{document}
add a comment |
The missing text has been added as label
s to the nodes. I defined a style addlabel
for convenience. The amsmath
package is added for the text
macro.
For the missing lines, I use the syntax of the calc
library to draw a line relative to the n0
node, and I add a coordinate
at each end of that line (l1
and l2
). The next two lines are drawn with perpendicular coordinates, e.g. (l1 |- n2)
is the point that has the x-coordinate of l1
and the y-coordinate of n2
. This makes it easy to draw the lines of the same length.
I also removed the xcolor
package, as that is already loaded by tikz
, and moved the dvipsnames
option to the documentclass.
I don't know where floatfoot
comes from, so that is commented out, and the extra end{tikzpicture}
you had is removed. I also commented the linespread
, do you really want that? (Personally I'd remove it.)
documentclass[12pt,twoside,dvipsnames]{book}%{book}
usepackage{amsmath}
usepackage{tikz}
usetikzlibrary{calc}
begin{document}
begin{figure}
centering
begin{tikzpicture}[
font = footnotesize,
edge from parent/.style = {draw ,thin},
SN/.style = {%solid node
circle, inner sep=1.2 ,fill=blue,
},
HN/.style = {%hollow node
circle, inner sep=1.2, draw=blue,
},
addlabel/.style={label={[align=center]below:#1}},
level distance = 25mm,
level 1/.style = {sibling distance=50mm},
level 2/.style = {sibling distance=40mm}
]
%---
%linespread{0.8}
%-------
node (n0) [HN] {}
child{ node (n1) [SN,addlabel={$pi_1=text{equation 1}$\$u_1=text{utility 1}$}] {}
edge from parent node[left]{$n_c$ buy}
}
child{ node (n2) [SN] {}
child{node[HN,addlabel={$pi_2=text{equation 2}$\$u_2=text{utility 2}$}] {}
edge from parent node[left]{$1-n_c$ buy}}
child{node[HN,addlabel={0\0}] (n3) {}
edge from parent node[right]{not buy}}
edge from parent node[right]{not buy}
};
draw[<-,shorten <=1pt]
(n0) -- + (2,1) node[right,align=left] {Entrepreneur\
sets $P_c$ };
draw[<-,shorten <=1pt]
(n2) -- + (2,1) node[right,align=left] {Entrepreneur\
sets $P_r$ };
draw [dotted] ($(n0.center)+(-4cm,0)$) coordinate (l1) -- ($(n0.center) + (6cm,0)$) coordinate (l2) node[right] {$t=0$};
draw [dotted] (l1 |- n2) -- (l2 |- n2) node[right] {$t=1$};
draw [dotted] (l1 |- n3) -- (l2 |- n3) node[right] {$t=3$};
end{tikzpicture}
caption{Timing of game}
label{Testing label}
% floatfoot{textit{Source}: Own illustration}
end{figure}
end{document}
The missing text has been added as label
s to the nodes. I defined a style addlabel
for convenience. The amsmath
package is added for the text
macro.
For the missing lines, I use the syntax of the calc
library to draw a line relative to the n0
node, and I add a coordinate
at each end of that line (l1
and l2
). The next two lines are drawn with perpendicular coordinates, e.g. (l1 |- n2)
is the point that has the x-coordinate of l1
and the y-coordinate of n2
. This makes it easy to draw the lines of the same length.
I also removed the xcolor
package, as that is already loaded by tikz
, and moved the dvipsnames
option to the documentclass.
I don't know where floatfoot
comes from, so that is commented out, and the extra end{tikzpicture}
you had is removed. I also commented the linespread
, do you really want that? (Personally I'd remove it.)
documentclass[12pt,twoside,dvipsnames]{book}%{book}
usepackage{amsmath}
usepackage{tikz}
usetikzlibrary{calc}
begin{document}
begin{figure}
centering
begin{tikzpicture}[
font = footnotesize,
edge from parent/.style = {draw ,thin},
SN/.style = {%solid node
circle, inner sep=1.2 ,fill=blue,
},
HN/.style = {%hollow node
circle, inner sep=1.2, draw=blue,
},
addlabel/.style={label={[align=center]below:#1}},
level distance = 25mm,
level 1/.style = {sibling distance=50mm},
level 2/.style = {sibling distance=40mm}
]
%---
%linespread{0.8}
%-------
node (n0) [HN] {}
child{ node (n1) [SN,addlabel={$pi_1=text{equation 1}$\$u_1=text{utility 1}$}] {}
edge from parent node[left]{$n_c$ buy}
}
child{ node (n2) [SN] {}
child{node[HN,addlabel={$pi_2=text{equation 2}$\$u_2=text{utility 2}$}] {}
edge from parent node[left]{$1-n_c$ buy}}
child{node[HN,addlabel={0\0}] (n3) {}
edge from parent node[right]{not buy}}
edge from parent node[right]{not buy}
};
draw[<-,shorten <=1pt]
(n0) -- + (2,1) node[right,align=left] {Entrepreneur\
sets $P_c$ };
draw[<-,shorten <=1pt]
(n2) -- + (2,1) node[right,align=left] {Entrepreneur\
sets $P_r$ };
draw [dotted] ($(n0.center)+(-4cm,0)$) coordinate (l1) -- ($(n0.center) + (6cm,0)$) coordinate (l2) node[right] {$t=0$};
draw [dotted] (l1 |- n2) -- (l2 |- n2) node[right] {$t=1$};
draw [dotted] (l1 |- n3) -- (l2 |- n3) node[right] {$t=3$};
end{tikzpicture}
caption{Timing of game}
label{Testing label}
% floatfoot{textit{Source}: Own illustration}
end{figure}
end{document}
answered May 27 '16 at 20:11
Torbjørn T.Torbjørn T.
158k13255444
158k13255444
add a comment |
add a comment |
A solution with forest
Code
documentclass[12pt,twoside]{book}%{book}
usepackage[a4paper, hmargin={2.5cm, 2.5cm}, vmargin={2.5cm, 2.5cm},bindingoffset=6mm]{geometry}
usepackage{forest,mathtools}
forestset{
declare toks={elo}{}, % Edge Label Options
anchors/.style={anchor=#1,child anchor=#1,parent anchor=#1},
dot/.style={tikz={draw[blue,#1] (.child anchor) circle[radius=1.5pt];}},
decision edge label/.style n args=3{
edge label/.expanded={node[midway,auto=#1,anchor=#2,forestoption{elo}]{strutunexpanded{#3}}}
},
decision/.style={if n=1
{decision edge label={left}{east}{#1}}
{decision edge label={right}{west}{#1}}
},
game tree/.style={
for tree={
s sep=30mm,l=25mm,
if n children=0{anchors=north}{
if n=1{anchors=south east}{anchors=south west}},
math content,
},
anchors=south,
dot={fill=white},for descendants={dot={fill=blue}},
delay={for descendants={split option={content}{;}{decision,content}}},
},
}
newcommandpayoff[1]{begin{matrix}#1end{matrix}}
begin{document}
begin{figure}
centering
begin{forest}
game tree,
[
[$n_c$ buy;payoff{pi_1=text{equation 1} \ u_1=text{utility 1}}]
[not buy;
[$1-n_c$ buy;payoff{pi_2=text{equation 2} \ u_2=text{utility 2}},dot={fill=white}]
[not buy;payoff{0 \ 0},dot={fill=white}]
]
]
draw[<-,shorten <=3pt]
(!r.anchor) -- + (2,1) node[right,align=left] {Entrepreneur\
sets $P_c$ };
draw[<-,shorten <=3pt]
(!2.anchor) -- + (2,1) node[right,align=left] {Entrepreneur\
sets $P_r$ };
draw[dotted](current bounding box.west|-!r.anchor)--(current bounding box.east|-!r.anchor)node[right,overlay]{$t=0$};
draw[dotted](current bounding box.west|-!2.anchor)--(current bounding box.east|-!2.anchor)node[right,overlay]{$t=1$};
draw[dotted](current bounding box.west|-!21.anchor)--(current bounding box.east|-!22.anchor)node[right,overlay]{$t=2$};
end{forest}
caption{Timing of game}
label{Testing label}
% floatfoot{textit{Source}: Own illustration}
end{figure}
end{document}
Output
add a comment |
A solution with forest
Code
documentclass[12pt,twoside]{book}%{book}
usepackage[a4paper, hmargin={2.5cm, 2.5cm}, vmargin={2.5cm, 2.5cm},bindingoffset=6mm]{geometry}
usepackage{forest,mathtools}
forestset{
declare toks={elo}{}, % Edge Label Options
anchors/.style={anchor=#1,child anchor=#1,parent anchor=#1},
dot/.style={tikz={draw[blue,#1] (.child anchor) circle[radius=1.5pt];}},
decision edge label/.style n args=3{
edge label/.expanded={node[midway,auto=#1,anchor=#2,forestoption{elo}]{strutunexpanded{#3}}}
},
decision/.style={if n=1
{decision edge label={left}{east}{#1}}
{decision edge label={right}{west}{#1}}
},
game tree/.style={
for tree={
s sep=30mm,l=25mm,
if n children=0{anchors=north}{
if n=1{anchors=south east}{anchors=south west}},
math content,
},
anchors=south,
dot={fill=white},for descendants={dot={fill=blue}},
delay={for descendants={split option={content}{;}{decision,content}}},
},
}
newcommandpayoff[1]{begin{matrix}#1end{matrix}}
begin{document}
begin{figure}
centering
begin{forest}
game tree,
[
[$n_c$ buy;payoff{pi_1=text{equation 1} \ u_1=text{utility 1}}]
[not buy;
[$1-n_c$ buy;payoff{pi_2=text{equation 2} \ u_2=text{utility 2}},dot={fill=white}]
[not buy;payoff{0 \ 0},dot={fill=white}]
]
]
draw[<-,shorten <=3pt]
(!r.anchor) -- + (2,1) node[right,align=left] {Entrepreneur\
sets $P_c$ };
draw[<-,shorten <=3pt]
(!2.anchor) -- + (2,1) node[right,align=left] {Entrepreneur\
sets $P_r$ };
draw[dotted](current bounding box.west|-!r.anchor)--(current bounding box.east|-!r.anchor)node[right,overlay]{$t=0$};
draw[dotted](current bounding box.west|-!2.anchor)--(current bounding box.east|-!2.anchor)node[right,overlay]{$t=1$};
draw[dotted](current bounding box.west|-!21.anchor)--(current bounding box.east|-!22.anchor)node[right,overlay]{$t=2$};
end{forest}
caption{Timing of game}
label{Testing label}
% floatfoot{textit{Source}: Own illustration}
end{figure}
end{document}
Output
add a comment |
A solution with forest
Code
documentclass[12pt,twoside]{book}%{book}
usepackage[a4paper, hmargin={2.5cm, 2.5cm}, vmargin={2.5cm, 2.5cm},bindingoffset=6mm]{geometry}
usepackage{forest,mathtools}
forestset{
declare toks={elo}{}, % Edge Label Options
anchors/.style={anchor=#1,child anchor=#1,parent anchor=#1},
dot/.style={tikz={draw[blue,#1] (.child anchor) circle[radius=1.5pt];}},
decision edge label/.style n args=3{
edge label/.expanded={node[midway,auto=#1,anchor=#2,forestoption{elo}]{strutunexpanded{#3}}}
},
decision/.style={if n=1
{decision edge label={left}{east}{#1}}
{decision edge label={right}{west}{#1}}
},
game tree/.style={
for tree={
s sep=30mm,l=25mm,
if n children=0{anchors=north}{
if n=1{anchors=south east}{anchors=south west}},
math content,
},
anchors=south,
dot={fill=white},for descendants={dot={fill=blue}},
delay={for descendants={split option={content}{;}{decision,content}}},
},
}
newcommandpayoff[1]{begin{matrix}#1end{matrix}}
begin{document}
begin{figure}
centering
begin{forest}
game tree,
[
[$n_c$ buy;payoff{pi_1=text{equation 1} \ u_1=text{utility 1}}]
[not buy;
[$1-n_c$ buy;payoff{pi_2=text{equation 2} \ u_2=text{utility 2}},dot={fill=white}]
[not buy;payoff{0 \ 0},dot={fill=white}]
]
]
draw[<-,shorten <=3pt]
(!r.anchor) -- + (2,1) node[right,align=left] {Entrepreneur\
sets $P_c$ };
draw[<-,shorten <=3pt]
(!2.anchor) -- + (2,1) node[right,align=left] {Entrepreneur\
sets $P_r$ };
draw[dotted](current bounding box.west|-!r.anchor)--(current bounding box.east|-!r.anchor)node[right,overlay]{$t=0$};
draw[dotted](current bounding box.west|-!2.anchor)--(current bounding box.east|-!2.anchor)node[right,overlay]{$t=1$};
draw[dotted](current bounding box.west|-!21.anchor)--(current bounding box.east|-!22.anchor)node[right,overlay]{$t=2$};
end{forest}
caption{Timing of game}
label{Testing label}
% floatfoot{textit{Source}: Own illustration}
end{figure}
end{document}
Output
A solution with forest
Code
documentclass[12pt,twoside]{book}%{book}
usepackage[a4paper, hmargin={2.5cm, 2.5cm}, vmargin={2.5cm, 2.5cm},bindingoffset=6mm]{geometry}
usepackage{forest,mathtools}
forestset{
declare toks={elo}{}, % Edge Label Options
anchors/.style={anchor=#1,child anchor=#1,parent anchor=#1},
dot/.style={tikz={draw[blue,#1] (.child anchor) circle[radius=1.5pt];}},
decision edge label/.style n args=3{
edge label/.expanded={node[midway,auto=#1,anchor=#2,forestoption{elo}]{strutunexpanded{#3}}}
},
decision/.style={if n=1
{decision edge label={left}{east}{#1}}
{decision edge label={right}{west}{#1}}
},
game tree/.style={
for tree={
s sep=30mm,l=25mm,
if n children=0{anchors=north}{
if n=1{anchors=south east}{anchors=south west}},
math content,
},
anchors=south,
dot={fill=white},for descendants={dot={fill=blue}},
delay={for descendants={split option={content}{;}{decision,content}}},
},
}
newcommandpayoff[1]{begin{matrix}#1end{matrix}}
begin{document}
begin{figure}
centering
begin{forest}
game tree,
[
[$n_c$ buy;payoff{pi_1=text{equation 1} \ u_1=text{utility 1}}]
[not buy;
[$1-n_c$ buy;payoff{pi_2=text{equation 2} \ u_2=text{utility 2}},dot={fill=white}]
[not buy;payoff{0 \ 0},dot={fill=white}]
]
]
draw[<-,shorten <=3pt]
(!r.anchor) -- + (2,1) node[right,align=left] {Entrepreneur\
sets $P_c$ };
draw[<-,shorten <=3pt]
(!2.anchor) -- + (2,1) node[right,align=left] {Entrepreneur\
sets $P_r$ };
draw[dotted](current bounding box.west|-!r.anchor)--(current bounding box.east|-!r.anchor)node[right,overlay]{$t=0$};
draw[dotted](current bounding box.west|-!2.anchor)--(current bounding box.east|-!2.anchor)node[right,overlay]{$t=1$};
draw[dotted](current bounding box.west|-!21.anchor)--(current bounding box.east|-!22.anchor)node[right,overlay]{$t=2$};
end{forest}
caption{Timing of game}
label{Testing label}
% floatfoot{textit{Source}: Own illustration}
end{figure}
end{document}
Output
answered May 27 '16 at 21:19
Herr K.Herr K.
14k43483
14k43483
add a comment |
add a comment |
A shorter but inflexible forest
implementation:
Code
documentclass[tikz]{standalone}
usepackage{forest}usetikzlibrary{arrows.meta}
begin{document}
begin{forest}
Pin/.style={pin={[pin edge={thin,shorten <=4pgflinewidth,black,{Latex[round]}-,
to path={-- (tikztotarget.west)}}, pin distance=1.5cm, align=left]
10:Entrepreneur\ sets $P_#1$}},
buy/.style={edge label={node[inner sep=.1667em, /forest/if level=2{near end}{midway},
/forest/if n=1{above left}{above right}] {#1 buy}}},
c/.style={node options={circle,fill,outer sep=0pt,inner sep=.4mm},anchor=center},
foo/.style={anchor=parent, child anchor=parent, node options={align=left,
append after command={(.parent) edge[fill,to path={circle[radius=.4mm]}] ()}},
content={$pi_{pgfmathprint{level}} = {}$equation pgfmathprint{level}\
$u_{pgfmathprint{level}} = {}$utility pgfmathprint{level}}},
for tree={l sep=2.5cm, s sep*=5,if n=1{alias/.wrap pgfmath arg={level-#1}{level()}}{}}
[, c, Pin=c, alias=level-0
[, foo, buy=$n_c$]
[, c, buy=not, Pin=r
[, foo, buy=$1-n_c$]
[, foo, content={0\0}, buy=not] ] ]
path(current bounding box.west)coordinate(cbbw)(current bounding box.east)coordinate(cbbe);
foreach l[evaluate={a={l==0?"center":"north"};}] in {0,...,2}
draw[dashed] (cbbw |- level-l.a) -- (cbbe |- level-l.a) node[right] {$t=l$};
end{forest}
end{document}
Nice ;) Do you neednode options
forc
?
– cfr
May 28 '16 at 2:11
add a comment |
A shorter but inflexible forest
implementation:
Code
documentclass[tikz]{standalone}
usepackage{forest}usetikzlibrary{arrows.meta}
begin{document}
begin{forest}
Pin/.style={pin={[pin edge={thin,shorten <=4pgflinewidth,black,{Latex[round]}-,
to path={-- (tikztotarget.west)}}, pin distance=1.5cm, align=left]
10:Entrepreneur\ sets $P_#1$}},
buy/.style={edge label={node[inner sep=.1667em, /forest/if level=2{near end}{midway},
/forest/if n=1{above left}{above right}] {#1 buy}}},
c/.style={node options={circle,fill,outer sep=0pt,inner sep=.4mm},anchor=center},
foo/.style={anchor=parent, child anchor=parent, node options={align=left,
append after command={(.parent) edge[fill,to path={circle[radius=.4mm]}] ()}},
content={$pi_{pgfmathprint{level}} = {}$equation pgfmathprint{level}\
$u_{pgfmathprint{level}} = {}$utility pgfmathprint{level}}},
for tree={l sep=2.5cm, s sep*=5,if n=1{alias/.wrap pgfmath arg={level-#1}{level()}}{}}
[, c, Pin=c, alias=level-0
[, foo, buy=$n_c$]
[, c, buy=not, Pin=r
[, foo, buy=$1-n_c$]
[, foo, content={0\0}, buy=not] ] ]
path(current bounding box.west)coordinate(cbbw)(current bounding box.east)coordinate(cbbe);
foreach l[evaluate={a={l==0?"center":"north"};}] in {0,...,2}
draw[dashed] (cbbw |- level-l.a) -- (cbbe |- level-l.a) node[right] {$t=l$};
end{forest}
end{document}
Nice ;) Do you neednode options
forc
?
– cfr
May 28 '16 at 2:11
add a comment |
A shorter but inflexible forest
implementation:
Code
documentclass[tikz]{standalone}
usepackage{forest}usetikzlibrary{arrows.meta}
begin{document}
begin{forest}
Pin/.style={pin={[pin edge={thin,shorten <=4pgflinewidth,black,{Latex[round]}-,
to path={-- (tikztotarget.west)}}, pin distance=1.5cm, align=left]
10:Entrepreneur\ sets $P_#1$}},
buy/.style={edge label={node[inner sep=.1667em, /forest/if level=2{near end}{midway},
/forest/if n=1{above left}{above right}] {#1 buy}}},
c/.style={node options={circle,fill,outer sep=0pt,inner sep=.4mm},anchor=center},
foo/.style={anchor=parent, child anchor=parent, node options={align=left,
append after command={(.parent) edge[fill,to path={circle[radius=.4mm]}] ()}},
content={$pi_{pgfmathprint{level}} = {}$equation pgfmathprint{level}\
$u_{pgfmathprint{level}} = {}$utility pgfmathprint{level}}},
for tree={l sep=2.5cm, s sep*=5,if n=1{alias/.wrap pgfmath arg={level-#1}{level()}}{}}
[, c, Pin=c, alias=level-0
[, foo, buy=$n_c$]
[, c, buy=not, Pin=r
[, foo, buy=$1-n_c$]
[, foo, content={0\0}, buy=not] ] ]
path(current bounding box.west)coordinate(cbbw)(current bounding box.east)coordinate(cbbe);
foreach l[evaluate={a={l==0?"center":"north"};}] in {0,...,2}
draw[dashed] (cbbw |- level-l.a) -- (cbbe |- level-l.a) node[right] {$t=l$};
end{forest}
end{document}
A shorter but inflexible forest
implementation:
Code
documentclass[tikz]{standalone}
usepackage{forest}usetikzlibrary{arrows.meta}
begin{document}
begin{forest}
Pin/.style={pin={[pin edge={thin,shorten <=4pgflinewidth,black,{Latex[round]}-,
to path={-- (tikztotarget.west)}}, pin distance=1.5cm, align=left]
10:Entrepreneur\ sets $P_#1$}},
buy/.style={edge label={node[inner sep=.1667em, /forest/if level=2{near end}{midway},
/forest/if n=1{above left}{above right}] {#1 buy}}},
c/.style={node options={circle,fill,outer sep=0pt,inner sep=.4mm},anchor=center},
foo/.style={anchor=parent, child anchor=parent, node options={align=left,
append after command={(.parent) edge[fill,to path={circle[radius=.4mm]}] ()}},
content={$pi_{pgfmathprint{level}} = {}$equation pgfmathprint{level}\
$u_{pgfmathprint{level}} = {}$utility pgfmathprint{level}}},
for tree={l sep=2.5cm, s sep*=5,if n=1{alias/.wrap pgfmath arg={level-#1}{level()}}{}}
[, c, Pin=c, alias=level-0
[, foo, buy=$n_c$]
[, c, buy=not, Pin=r
[, foo, buy=$1-n_c$]
[, foo, content={0\0}, buy=not] ] ]
path(current bounding box.west)coordinate(cbbw)(current bounding box.east)coordinate(cbbe);
foreach l[evaluate={a={l==0?"center":"north"};}] in {0,...,2}
draw[dashed] (cbbw |- level-l.a) -- (cbbe |- level-l.a) node[right] {$t=l$};
end{forest}
end{document}
answered May 28 '16 at 1:37
QrrbrbirlbelQrrbrbirlbel
77.8k4184317
77.8k4184317
Nice ;) Do you neednode options
forc
?
– cfr
May 28 '16 at 2:11
add a comment |
Nice ;) Do you neednode options
forc
?
– cfr
May 28 '16 at 2:11
Nice ;) Do you need
node options
for c
?– cfr
May 28 '16 at 2:11
Nice ;) Do you need
node options
for c
?– cfr
May 28 '16 at 2:11
add a comment |
This is a demonstration using an experimental package justtrees
. (Code available on request.)
justtrees
is a forest
-based package designed to make it easy to align labels horizontally with the different levels of the tree. Labels may be aligned to the left and/or right of the tree and formatting may be configured globally. just={<label>}
adds a label, by default, to the right as shown here.
The backgrounds
library is used to ensure the dotted lines are drawn behind the tree and arrows.meta
is used for the circles which are filled with white or blue to obscure the dots. justtrees
automatically figures out where to place the labels on the right. Since the package is based on forest
, forest
's facilities are used to automate the addition of these labels, the placement and format of edge labels and the overall style of the tree.
Once configured, the tree itself is specified quite concisely with
[, pin=45:{Entrepreneur\sets $P_c$}
[{$pi_1 = text{equation 1}$\$u_1 = text{utility 1}$}, edge label={$n_c$ buy}
]
[, edge label=not buy, pin=45:{Entrepreneur\sets $P_r$}
[{$pi_2 = text{equation 2}$\$u_2 = text{utility 2}$}, edge label={$1 - n_c$ buy}
]
[$0$\$0$, edge label=not buy
]
]
]
documentclass[tikz,border=10pt,multi]{standalone}
usepackage{justtrees,amsmath}% justtrees rev 4959
usetikzlibrary{arrows.meta,backgrounds}
begin{document}
begin{justtree}
{
/tikz/every pin/.append style={pin distance=40pt, align=left},
/tikz/every pin edge/.append style={shorten <=2pt, {Stealth}-, draw=black},
delay={
where n children=0{%
label/.wrap pgfmath arg={[align=center, label distance=5pt]below:#1}{content()},
content={},
}{},
for tree={
if n=1{
edge label/.wrap value={node [midway, left, anchor=mid east] {#1}},
}{
edge label/.wrap value={node [midway, right, anchor=mid west] {#1}},
},
}
},
for tree={%
l sep'+=70pt,
s sep'+=80pt,
+edge={%
shorten >=-2pt,
shorten <=-2pt,
},
if level=3{%
+edge={%
{Circle[width=4pt,length=4pt,blue,fill=blue]}-{Circle[width=4pt,length=4pt,blue,fill=white]},
},
}{%
+edge={%
{Circle[width=4pt,length=4pt,blue,fill=white]}-{Circle[width=4pt,length=4pt,blue,fill=white]},
},
},
},
before typesetting nodes={%
for nodewalk={fake=r,L,ancestors}{%
if level=0{}{%
just/.wrap pgfmath arg={$t=#1$}{int(level()-1)},
tikz+/.wrap pgfmath arg={%
scoped[on background layer]{%
draw [densely dotted] (right just #1) -- (right just #1 -| just tree west);
}
}{level()}
}
}
},
just format={anchor=west},
}
[, pin=45:{Entrepreneur\sets $P_c$}
[{$pi_1 = text{equation 1}$\$u_1 = text{utility 1}$}, edge label={$n_c$ buy}
]
[, edge label=not buy, pin=45:{Entrepreneur\sets $P_r$}
[{$pi_2 = text{equation 2}$\$u_2 = text{utility 2}$}, edge label={$1 - n_c$ buy}
]
[$0$\$0$, edge label=not buy
]
]
]
end{justtree}
end{document}
add a comment |
This is a demonstration using an experimental package justtrees
. (Code available on request.)
justtrees
is a forest
-based package designed to make it easy to align labels horizontally with the different levels of the tree. Labels may be aligned to the left and/or right of the tree and formatting may be configured globally. just={<label>}
adds a label, by default, to the right as shown here.
The backgrounds
library is used to ensure the dotted lines are drawn behind the tree and arrows.meta
is used for the circles which are filled with white or blue to obscure the dots. justtrees
automatically figures out where to place the labels on the right. Since the package is based on forest
, forest
's facilities are used to automate the addition of these labels, the placement and format of edge labels and the overall style of the tree.
Once configured, the tree itself is specified quite concisely with
[, pin=45:{Entrepreneur\sets $P_c$}
[{$pi_1 = text{equation 1}$\$u_1 = text{utility 1}$}, edge label={$n_c$ buy}
]
[, edge label=not buy, pin=45:{Entrepreneur\sets $P_r$}
[{$pi_2 = text{equation 2}$\$u_2 = text{utility 2}$}, edge label={$1 - n_c$ buy}
]
[$0$\$0$, edge label=not buy
]
]
]
documentclass[tikz,border=10pt,multi]{standalone}
usepackage{justtrees,amsmath}% justtrees rev 4959
usetikzlibrary{arrows.meta,backgrounds}
begin{document}
begin{justtree}
{
/tikz/every pin/.append style={pin distance=40pt, align=left},
/tikz/every pin edge/.append style={shorten <=2pt, {Stealth}-, draw=black},
delay={
where n children=0{%
label/.wrap pgfmath arg={[align=center, label distance=5pt]below:#1}{content()},
content={},
}{},
for tree={
if n=1{
edge label/.wrap value={node [midway, left, anchor=mid east] {#1}},
}{
edge label/.wrap value={node [midway, right, anchor=mid west] {#1}},
},
}
},
for tree={%
l sep'+=70pt,
s sep'+=80pt,
+edge={%
shorten >=-2pt,
shorten <=-2pt,
},
if level=3{%
+edge={%
{Circle[width=4pt,length=4pt,blue,fill=blue]}-{Circle[width=4pt,length=4pt,blue,fill=white]},
},
}{%
+edge={%
{Circle[width=4pt,length=4pt,blue,fill=white]}-{Circle[width=4pt,length=4pt,blue,fill=white]},
},
},
},
before typesetting nodes={%
for nodewalk={fake=r,L,ancestors}{%
if level=0{}{%
just/.wrap pgfmath arg={$t=#1$}{int(level()-1)},
tikz+/.wrap pgfmath arg={%
scoped[on background layer]{%
draw [densely dotted] (right just #1) -- (right just #1 -| just tree west);
}
}{level()}
}
}
},
just format={anchor=west},
}
[, pin=45:{Entrepreneur\sets $P_c$}
[{$pi_1 = text{equation 1}$\$u_1 = text{utility 1}$}, edge label={$n_c$ buy}
]
[, edge label=not buy, pin=45:{Entrepreneur\sets $P_r$}
[{$pi_2 = text{equation 2}$\$u_2 = text{utility 2}$}, edge label={$1 - n_c$ buy}
]
[$0$\$0$, edge label=not buy
]
]
]
end{justtree}
end{document}
add a comment |
This is a demonstration using an experimental package justtrees
. (Code available on request.)
justtrees
is a forest
-based package designed to make it easy to align labels horizontally with the different levels of the tree. Labels may be aligned to the left and/or right of the tree and formatting may be configured globally. just={<label>}
adds a label, by default, to the right as shown here.
The backgrounds
library is used to ensure the dotted lines are drawn behind the tree and arrows.meta
is used for the circles which are filled with white or blue to obscure the dots. justtrees
automatically figures out where to place the labels on the right. Since the package is based on forest
, forest
's facilities are used to automate the addition of these labels, the placement and format of edge labels and the overall style of the tree.
Once configured, the tree itself is specified quite concisely with
[, pin=45:{Entrepreneur\sets $P_c$}
[{$pi_1 = text{equation 1}$\$u_1 = text{utility 1}$}, edge label={$n_c$ buy}
]
[, edge label=not buy, pin=45:{Entrepreneur\sets $P_r$}
[{$pi_2 = text{equation 2}$\$u_2 = text{utility 2}$}, edge label={$1 - n_c$ buy}
]
[$0$\$0$, edge label=not buy
]
]
]
documentclass[tikz,border=10pt,multi]{standalone}
usepackage{justtrees,amsmath}% justtrees rev 4959
usetikzlibrary{arrows.meta,backgrounds}
begin{document}
begin{justtree}
{
/tikz/every pin/.append style={pin distance=40pt, align=left},
/tikz/every pin edge/.append style={shorten <=2pt, {Stealth}-, draw=black},
delay={
where n children=0{%
label/.wrap pgfmath arg={[align=center, label distance=5pt]below:#1}{content()},
content={},
}{},
for tree={
if n=1{
edge label/.wrap value={node [midway, left, anchor=mid east] {#1}},
}{
edge label/.wrap value={node [midway, right, anchor=mid west] {#1}},
},
}
},
for tree={%
l sep'+=70pt,
s sep'+=80pt,
+edge={%
shorten >=-2pt,
shorten <=-2pt,
},
if level=3{%
+edge={%
{Circle[width=4pt,length=4pt,blue,fill=blue]}-{Circle[width=4pt,length=4pt,blue,fill=white]},
},
}{%
+edge={%
{Circle[width=4pt,length=4pt,blue,fill=white]}-{Circle[width=4pt,length=4pt,blue,fill=white]},
},
},
},
before typesetting nodes={%
for nodewalk={fake=r,L,ancestors}{%
if level=0{}{%
just/.wrap pgfmath arg={$t=#1$}{int(level()-1)},
tikz+/.wrap pgfmath arg={%
scoped[on background layer]{%
draw [densely dotted] (right just #1) -- (right just #1 -| just tree west);
}
}{level()}
}
}
},
just format={anchor=west},
}
[, pin=45:{Entrepreneur\sets $P_c$}
[{$pi_1 = text{equation 1}$\$u_1 = text{utility 1}$}, edge label={$n_c$ buy}
]
[, edge label=not buy, pin=45:{Entrepreneur\sets $P_r$}
[{$pi_2 = text{equation 2}$\$u_2 = text{utility 2}$}, edge label={$1 - n_c$ buy}
]
[$0$\$0$, edge label=not buy
]
]
]
end{justtree}
end{document}
This is a demonstration using an experimental package justtrees
. (Code available on request.)
justtrees
is a forest
-based package designed to make it easy to align labels horizontally with the different levels of the tree. Labels may be aligned to the left and/or right of the tree and formatting may be configured globally. just={<label>}
adds a label, by default, to the right as shown here.
The backgrounds
library is used to ensure the dotted lines are drawn behind the tree and arrows.meta
is used for the circles which are filled with white or blue to obscure the dots. justtrees
automatically figures out where to place the labels on the right. Since the package is based on forest
, forest
's facilities are used to automate the addition of these labels, the placement and format of edge labels and the overall style of the tree.
Once configured, the tree itself is specified quite concisely with
[, pin=45:{Entrepreneur\sets $P_c$}
[{$pi_1 = text{equation 1}$\$u_1 = text{utility 1}$}, edge label={$n_c$ buy}
]
[, edge label=not buy, pin=45:{Entrepreneur\sets $P_r$}
[{$pi_2 = text{equation 2}$\$u_2 = text{utility 2}$}, edge label={$1 - n_c$ buy}
]
[$0$\$0$, edge label=not buy
]
]
]
documentclass[tikz,border=10pt,multi]{standalone}
usepackage{justtrees,amsmath}% justtrees rev 4959
usetikzlibrary{arrows.meta,backgrounds}
begin{document}
begin{justtree}
{
/tikz/every pin/.append style={pin distance=40pt, align=left},
/tikz/every pin edge/.append style={shorten <=2pt, {Stealth}-, draw=black},
delay={
where n children=0{%
label/.wrap pgfmath arg={[align=center, label distance=5pt]below:#1}{content()},
content={},
}{},
for tree={
if n=1{
edge label/.wrap value={node [midway, left, anchor=mid east] {#1}},
}{
edge label/.wrap value={node [midway, right, anchor=mid west] {#1}},
},
}
},
for tree={%
l sep'+=70pt,
s sep'+=80pt,
+edge={%
shorten >=-2pt,
shorten <=-2pt,
},
if level=3{%
+edge={%
{Circle[width=4pt,length=4pt,blue,fill=blue]}-{Circle[width=4pt,length=4pt,blue,fill=white]},
},
}{%
+edge={%
{Circle[width=4pt,length=4pt,blue,fill=white]}-{Circle[width=4pt,length=4pt,blue,fill=white]},
},
},
},
before typesetting nodes={%
for nodewalk={fake=r,L,ancestors}{%
if level=0{}{%
just/.wrap pgfmath arg={$t=#1$}{int(level()-1)},
tikz+/.wrap pgfmath arg={%
scoped[on background layer]{%
draw [densely dotted] (right just #1) -- (right just #1 -| just tree west);
}
}{level()}
}
}
},
just format={anchor=west},
}
[, pin=45:{Entrepreneur\sets $P_c$}
[{$pi_1 = text{equation 1}$\$u_1 = text{utility 1}$}, edge label={$n_c$ buy}
]
[, edge label=not buy, pin=45:{Entrepreneur\sets $P_r$}
[{$pi_2 = text{equation 2}$\$u_2 = text{utility 2}$}, edge label={$1 - n_c$ buy}
]
[$0$\$0$, edge label=not buy
]
]
]
end{justtree}
end{document}
edited May 27 '16 at 23:11
answered May 27 '16 at 23:04
cfrcfr
157k8191390
157k8191390
add a comment |
add a comment |
The istgame
package (version 2) provides macros for time-lines: xtTimeLineH
and xtTimeLineV
. It also provides macros for comments: xtCommentTo
and xtCommentFrom
.
Here is an example of using xtTimeLineH
and xtCommentTo
.
documentclass{standalone}
usepackage{amsmath}
usepackage{makecell}
usepackage{istgame}
begin{document}
begin{istgame}[font=footnotesize]
% tree
setistmathTF001
xtShowEndPoints
xtdistance{25mm}{50mm}
istroot(0)
istb{$n_c$ buy}[al]{makecell[l]{pi_1=text{equation 1}\u_1=text{utility 1}}}
istb{not buy}[ar]
endist
istroot(1)(0-2)
istb{$1-n_c$ buy}[al]{makecell[l]{pi_2=text{equation 2}\u_2=text{utility 2}}}
istb{not buy}[ar]{makecell{0\0}}
endist
% time-lines and comments
xtTimeLineH(0){-4cm}{6cm}{$t=0$}
xtTimeLineH(1){-4cm}{6cm}{$t=1$}
xtTimeLineH(1-1){-4cm}{6cm}{$t=2$}
xtCommentTo[solid](0)(2,1){makecell[l]{Entrepreneur\sets $P_c$}}[r]
xtCommentTo[solid](1)(2,1){makecell[l]{Entrepreneur\sets $P_r$}}[r]
end{istgame}
end{document}
add a comment |
The istgame
package (version 2) provides macros for time-lines: xtTimeLineH
and xtTimeLineV
. It also provides macros for comments: xtCommentTo
and xtCommentFrom
.
Here is an example of using xtTimeLineH
and xtCommentTo
.
documentclass{standalone}
usepackage{amsmath}
usepackage{makecell}
usepackage{istgame}
begin{document}
begin{istgame}[font=footnotesize]
% tree
setistmathTF001
xtShowEndPoints
xtdistance{25mm}{50mm}
istroot(0)
istb{$n_c$ buy}[al]{makecell[l]{pi_1=text{equation 1}\u_1=text{utility 1}}}
istb{not buy}[ar]
endist
istroot(1)(0-2)
istb{$1-n_c$ buy}[al]{makecell[l]{pi_2=text{equation 2}\u_2=text{utility 2}}}
istb{not buy}[ar]{makecell{0\0}}
endist
% time-lines and comments
xtTimeLineH(0){-4cm}{6cm}{$t=0$}
xtTimeLineH(1){-4cm}{6cm}{$t=1$}
xtTimeLineH(1-1){-4cm}{6cm}{$t=2$}
xtCommentTo[solid](0)(2,1){makecell[l]{Entrepreneur\sets $P_c$}}[r]
xtCommentTo[solid](1)(2,1){makecell[l]{Entrepreneur\sets $P_r$}}[r]
end{istgame}
end{document}
add a comment |
The istgame
package (version 2) provides macros for time-lines: xtTimeLineH
and xtTimeLineV
. It also provides macros for comments: xtCommentTo
and xtCommentFrom
.
Here is an example of using xtTimeLineH
and xtCommentTo
.
documentclass{standalone}
usepackage{amsmath}
usepackage{makecell}
usepackage{istgame}
begin{document}
begin{istgame}[font=footnotesize]
% tree
setistmathTF001
xtShowEndPoints
xtdistance{25mm}{50mm}
istroot(0)
istb{$n_c$ buy}[al]{makecell[l]{pi_1=text{equation 1}\u_1=text{utility 1}}}
istb{not buy}[ar]
endist
istroot(1)(0-2)
istb{$1-n_c$ buy}[al]{makecell[l]{pi_2=text{equation 2}\u_2=text{utility 2}}}
istb{not buy}[ar]{makecell{0\0}}
endist
% time-lines and comments
xtTimeLineH(0){-4cm}{6cm}{$t=0$}
xtTimeLineH(1){-4cm}{6cm}{$t=1$}
xtTimeLineH(1-1){-4cm}{6cm}{$t=2$}
xtCommentTo[solid](0)(2,1){makecell[l]{Entrepreneur\sets $P_c$}}[r]
xtCommentTo[solid](1)(2,1){makecell[l]{Entrepreneur\sets $P_r$}}[r]
end{istgame}
end{document}
The istgame
package (version 2) provides macros for time-lines: xtTimeLineH
and xtTimeLineV
. It also provides macros for comments: xtCommentTo
and xtCommentFrom
.
Here is an example of using xtTimeLineH
and xtCommentTo
.
documentclass{standalone}
usepackage{amsmath}
usepackage{makecell}
usepackage{istgame}
begin{document}
begin{istgame}[font=footnotesize]
% tree
setistmathTF001
xtShowEndPoints
xtdistance{25mm}{50mm}
istroot(0)
istb{$n_c$ buy}[al]{makecell[l]{pi_1=text{equation 1}\u_1=text{utility 1}}}
istb{not buy}[ar]
endist
istroot(1)(0-2)
istb{$1-n_c$ buy}[al]{makecell[l]{pi_2=text{equation 2}\u_2=text{utility 2}}}
istb{not buy}[ar]{makecell{0\0}}
endist
% time-lines and comments
xtTimeLineH(0){-4cm}{6cm}{$t=0$}
xtTimeLineH(1){-4cm}{6cm}{$t=1$}
xtTimeLineH(1-1){-4cm}{6cm}{$t=2$}
xtCommentTo[solid](0)(2,1){makecell[l]{Entrepreneur\sets $P_c$}}[r]
xtCommentTo[solid](1)(2,1){makecell[l]{Entrepreneur\sets $P_r$}}[r]
end{istgame}
end{document}
answered Mar 7 at 16:11
InSung ChoInSung Cho
88325
88325
add a comment |
add a comment |
Thanks for contributing an answer to TeX - LaTeX Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f311570%2fsmall-corrections-needed-for-game-tree%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Anyone that can help? :/
– Saud
May 26 '16 at 19:00
Perhaps, but it would really be appreciated if you could fix the code so that it compiles without errors.
– Torbjørn T.
May 27 '16 at 19:52