0

Diagram

Hey, I'm new to Stack Exchange and Latex. Can anyone help me with how to make this diagram in Latex? Can anyone help me with the code? Thank you

3
  • 5
    Welcome! There is the istgame package specifically for game trees. In general, trees can be created conveniently with the forest package.
    – user194703
    May 17, 2020 at 6:58
  • Can you give some link or anything?
    – HENAM
    May 17, 2020 at 7:06
  • 1
    ctan.org/pkg/istgame?lang=en and ctan.org/pkg/forest?lang=en .
    – user194703
    May 17, 2020 at 7:07

2 Answers 2

3

For game trees there is a specific package: istgame. The tag for this package was created only recently, so there are as of now not too many posts tagged istgame, but this may change. forest is generally a nice package for producing trees, and there are quite a few posts tagged forest. For your tree this package is certainly a possible choice.

\documentclass{article}
\usepackage[edges]{forest}
\begin{document}
\begin{forest}
el/.style={edge label={node[auto,pos=0.6]{$#1$}}},
el'/.style={edge label={node[auto,pos=0.6,swap]{$#1$}}},
for tree={math content,s sep+=4em,l sep+=1.5em,edge={semithick,-latex}}
[a
 [{(2,2)},el'=f]
 [b,el=g
  [{(0,0)},el'=n]
  [{(1,3)},el=y]
 ]
]
\end{forest}
\end{document}

enter image description here

However, it could very well be that istgame is closer to what you need on the long run. Needless to say that there are many more ways of producing trees, there is a tikz library called trees, the Graph Drawing Library trees, the tikz-qtree package and so on, i.e. this list is certainly not complete.

4
  • Thank you so much! It'll be of great help. It's really good to know new things in Latex.
    – HENAM
    May 17, 2020 at 9:35
  • Hey one more question, how to create arrows the above side of a node?
    – HENAM
    May 17, 2020 at 9:52
  • @HENAM I am sorry, I do not understand "how to create arrows the above side of a node". Do you mean the grow direction of the tree?
    – user194703
    May 17, 2020 at 13:10
  • Yes, so let's say, I need four arrows (2 on the lower side of a node and two on the upper side), and then, how to create a different node from any of those in those 4 arrows mentioned above?
    – HENAM
    May 18, 2020 at 3:40
3

Here is an example of using the istgame package:

enter image description here

\documentclass{standalone}

\usepackage{istgame}

\begin{document}

\begin{istgame}
\tikzset{oval node/.style={ellipse node,draw=none}}
\xtShowArrows[oval node]
\xtdistance{15mm}{30mm}
\istrooto(0){a}
  \istb{f}[al]{(2,2)}
  \istb[->-=.92]{g}[ar]
  \endist
\istrooto(1)(0-2){b}
  \istb{n}[al]{(0,0)}
  \istb{y}[ar]{(3,1)}
  \endist
\end{istgame}

\end{document}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .