This is my first attempt to create a figure using Tikz package in LaTex. (I am using TexMaker btw).
So I have taken example codes here and there and slightly modified to come up with the figure that I want, but the words in my figure is not aligned as I intended.
Here are the corrections that I wish to make:
- The wordings are written over the loop arrows -> I would like the wordings cleared away from the loop arrows.
- I would like to have words below the symbol. So, the wording 'resisted infection' to appear below the symbol zeta. Same for 'not cured'
- Same for the wordings associated with straight arrows. I would prefer to have symbols above the arrow as it is, but the wordings possibly below the arrow. (Or even just below the symbol and above arrow)
Here is my code:
\documentclass[11pt]{article}
\usepackage[margin=0.5in]{geometry}
\usepackage{amsmath}
\usepackage{tikz}
\usetikzlibrary{arrows}
\title{Discrete Time SIR Model - Stochastic analysis}
\author{Louis Kim}
\begin{document}
\maketitle
\tikzstyle{int}=[circle, draw, fill=blue!20, minimum size=3em, auto]
\tikzstyle{init} = [pin edge={loop,thin,black}]
\begin{tikzpicture}[node distance=5cm,auto,>=latex']
\node [int, pin={[init] $\zeta_{i,t}$,resisted infection}] (a) {$S$};
\node [int, pin={[init] $1-\delta$,not cured}] (c) [right of=a] {$I$};
\node [int] (e) [right of=c] {$R$};
\path[->] (a) edge node {$1-\zeta_{i,t}$, not resisted infection} (c);
\draw[->] (c) edge node {$\delta$, cured} (e) ;
\end{tikzpicture}
\end{document}
Any help would be greatly appreciated!!
Thanks,
Best Answer
The
pin
solution you chose is an interesting one, though I don’t it doesn’t work perfectly with theloop
option (there is alsoloop above
) as thepin distance
that places the pin node and the loop itself are independent.pin distance
.loop
ededge
.Use the
align=center
option that allows one to manually use line-breaks (\\
).You could use the same but then the two lines are too close to the line (I have introduced a little space).
I rather would use two nodes, where the second one uses the
swap
option so that it goes to the other side (swap
switches the direction of theauto
option).Code
Outputs