2

I am trying to reproduce the following figure:

enter image description here

I have been able to reproduce the figure almost entirely, but I am missing the arrows. This is my current attempt:

enter image description here

This is a MWE for my current figure:

\documentclass[margin=1pt]{standalone}
\usepackage{tikz} % To plot almost everything.
\usetikzlibrary{fit, calc, matrix, positioning, arrows.meta, intersections, through, backgrounds, patterns}

\begin{document}

\begin{tikzpicture}
\coordinate (a) at (0,0);
\coordinate (b) at (6,0);
\coordinate (c) at (3,4);
\coordinate (d) at (9,4);
\coordinate (e) at (3,-4);
\draw[cap=round,black!100,] (a) -- (b) node[pos=1/3,fill=white,rectangle,]{\footnotesize{Stay}} node[pos=2/3,fill=white,rectangle,]{\footnotesize{Go}} node[pos=1/2,rectangle,fill=white]{\footnotesize{\textbf{Chris}}};
\draw[cap=round,black!100,] (b) -- (c) node[pos=1/3,fill=white,rectangle,]{\footnotesize{Stay}} node[pos=2/3,fill=white,rectangle,]{\footnotesize{Go}} node[pos=1/2,rectangle,fill=white]{\footnotesize{\textbf{Barbara}}};
\draw[cap=round,black!100,] (a) -- (c) node[pos=1/3,fill=white,rectangle,]{\footnotesize{Stay}} node[pos=2/3,fill=white,rectangle,]{\footnotesize{Go}} node[pos=1/2,rectangle,fill=white]{\footnotesize{\textbf{John}}};
\draw[cap=round,black!100,] (c) -- (d) node[pos=1/3,fill=white,rectangle,]{\footnotesize{Stay}} node[pos=2/3,fill=white,rectangle,]{\footnotesize{Go}} node[pos=1/2,rectangle,fill=white]{\footnotesize{\textbf{Chris}}};
\draw[cap=round,black!100,] (d) -- (b) node[pos=1/3,fill=white,rectangle,]{\footnotesize{Stay}} node[pos=2/3,fill=white,rectangle,]{\footnotesize{Go}} node[pos=1/2,rectangle,fill=white]{\footnotesize{\textbf{John}}};
\draw[cap=round,black!100,] (a) -- (e) node[pos=1/3,fill=white,rectangle,]{\footnotesize{Stay}} node[pos=2/3,fill=white,rectangle,]{\footnotesize{Go}} node[pos=1/2,rectangle,fill=white]{\footnotesize{\textbf{John}}};
\draw[cap=round,black!100,] (e) -- (b) node[pos=1/3,fill=white,rectangle,]{\footnotesize{Stay}} node[pos=2/3,fill=white,rectangle,]{\footnotesize{Go}} node[pos=1/2,rectangle,fill=white]{\footnotesize{\textbf{Barbara}}};
\end{tikzpicture}

\end{document}

Does anybody know how to add the arrows?

NB: I DO NOT WANT TO MATCH THE OVERALL STYLE OF THE REFERENCE FIGURE, I JUST WANT TO ADD THE ARROWS.

Thank you all very much in advance for your time.

  • 1
    Add -> to the options for a line for the default arrow. If you want fancier arrow tips, see the arrows.meta library. – cfr Jun 16 '17 at 23:08
  • @cfr Thank you for your comment. I know how to (generally) draw arrows; but since the nodes located at ⅓ and ⅔ do not have a specific coordinate / names; I do not have a clue on how I should specify the desired arrows. Does it make sense? – Héctor Jun 16 '17 at 23:11
  • 1
    Why don't you name them? By the way, \footnotesize doesn't take an argument. It is a switch. – cfr Jun 16 '17 at 23:15
  • @cfr Thanks again for your comment. To be honest, I am not naming them because I do not seem to know how to do it, at the moment (all my attempts to do so end up in LaTex complaining in some way). And also, what do you mean with your comment about \footnotesize? (I'm kind of retarded, I know; and also I am learning LaTex by copy-pasting code snippets and trial and error until I get what I want...). – Héctor Jun 16 '17 at 23:19
1

A couple of things:

  • \footnotesize is a switch, so \footnotesize{abc} d is just the same as \footnotesize abc d. To limit the scope, you need the curly brackets around the switch, {\footnotesize abc d}, but that doesn't matter here because you are in a node anyhow.

  • Try to use styles rather than repeating the same settings over and over as it makes it easier to adapt your code later, if needed.

  • You can also use loops to repeat the same code with minor variations.

  • Nodes can be named just as coordinates can, \node (<node name>) {<node text>}; or \path ... node (<node name>) {<node text>} ....

For instance, the following adds some arrows to, and implements the suggestions above for, your example.

\documentclass[margin=10pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows.meta}
\begin{document}
\begin{tikzpicture}
  [
    cap=round,
    every node/.append style={fill=white, font=\footnotesize},
  ]
  \coordinate (a) at (0,0);
  \coordinate (b) at (6,0);
  \coordinate (c) at (3,4);
  \coordinate (d) at (9,4);
  \coordinate (e) at (3,-4);
  \foreach \i/\j/\k [count=\n] in {a/b/Chris,b/c/Barbara,a/c/John,c/d/Chris,d/b/John,a/e/John,e/b/Barbara}
  \draw (\i) -- (\j) node (s-\n) [pos=1/3] {Stay} node (g-\n) [pos=2/3] {Go} node (p-\n) [pos=1/2] {\textbf{\k}};
  % uncomment this line to show node names; comment for final version
  \foreach \i in {1,...,7} \foreach \j in {g,s,p} \node [font=\tiny\sffamily, inner sep=0pt, text=red, anchor=-135] at (\j-\i.45) {\j-\i};
  \foreach \i/\j in {g-2/s-4,g-2/s-5,g-3/g-2,g-3/g-1,s-3/s-2,s-3/s-1,g-1/g-6,g-1/g-7} \draw [-Latex] (\i) -- (\j);
\end{tikzpicture}
\end{document}

added arrows

Just add the pairs of node names you want and delete any you don't want. When you are done, comment out the line which is labelling the nodes in red, as you won't want that in your final version.

  • Thank you very much for your answer. In fact, your answer does not only generates the desired output, but it also helps to further understand how tikz works. This is (at least) twice as useful. – Héctor Jun 16 '17 at 23:36
  • @Héctor You are welcome! You were very clear about what you didn't know in your comments, so I tried to address those points :-). – cfr Jun 16 '17 at 23:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.