# Infectious disease compartmental flowchart on beamer using TikZ

I wanted to draw

Remark: The numbers on the diagram are not the part of the code. They show the sequence of precedence of the moving arrow.

MWE by editing this code:

\documentclass{beamer}
\usepackage[latin1]{inputenc}
\usepackage{times}
\usepackage{tikz}
\usepackage{verbatim}
\usetikzlibrary{arrows,shapes}

\begin{document}

\begin{frame}

\frametitle{flowchart}
\tikzstyle{format} = [draw, thin, fill=green]
\tikzstyle{form} = [draw, thin, fill=yellow]
\tikzstyle{med} = [draw, thin, fill=red]
\begin{figure}
\begin{tikzpicture}[node distance=3cm, auto,>=latex', thick]
\path[use as bounding box] (-1,0) rectangle (10,-2);
\path[->]<1-> node[format] (a1) {$A_1$};
\path[->]<2-> node[form, right of=dvi] (ps) {$A_2$}
node[format, below of=dvi] (b1) {$B_1$}
(a1) edge node {$\beta$} (ps);
\path[->]<3-> node[med, right of=ps] (b2) {$A_3$}
node[med, below of=ps] (b3) {$B_2$}
(b1) edge node {$\alpha$} (b3)
(ps) edge node {$\gamma$} (b2)
edge node[swap] {$\delta$} (b1)
edge (b3);
\path[<-]<4-> (a1) edge node  {$\delta$} (b3);
\path[<-, draw]<5-> (a1) -- +(0,1) -| node[near start] {$\lambda$} (b2);
\end{tikzpicture}
\end{figure}
\end{frame}
\end{document}

• in sketch you have noted 11 steps in appearing of node but in MWE you have only 5 and not complete image. Also is not clear to me, when appear nodes and dashed lines. – Zarko Jan 18 '17 at 11:05
• Some unrelated comments: 1) The figure environment is rather pointless here I'd say, it doesn't really do anything. 2) To motivate Zarko's use of the positioning library and its syntax, see tex.stackexchange.com/q/9386 3) And there are some newer alternatives to the times package are better I believe (\usepackage{newtxtext,newtxmath}), see e.g. tex.stackexchange.com/questions/669 – Torbjørn T. Jan 18 '17 at 13:05

As starting point since from your question is not clear to me when some part of image should appear:

\documentclass{beamer}
\usepackage[latin1]{inputenc}
\usepackage{times}
\usepackage{tikz}
\usepackage{verbatim}
\usetikzlibrary{arrows, positioning, quotes, shapes}

\begin{document}

\begin{frame}[fragile]
\frametitle{flowchart}
\begin{figure}
\begin{tikzpicture}[
node distance = 3cm, auto,>=latex', thick,
box/.style = {fill=#1,
draw, solid, thin, minimum size=9mm},
xs/.style = {xshift=#1mm}
]
\path[use as bounding box] (-1,0) rectangle (10,-2);
\path[->]<1-> coordinate (a0)
node (a1) [box=green, right=9mm of a0]  {$A_1$}
(a0) edge ["$\mu$"] (a1);
\path[draw,->]<2-> ([xs=2] a1.north) -- + (0,5mm) node[above] {$a$};
\path[draw,->]<3->
node (a2) [box=yellow, right=of a1]     {$A_2$}%dvi
node (b1) [box=yellow, below=of a1]     {$B_1$}%dvi
(a1) edge ["$\beta$"] (a2);
\path[draw,->]<4->
node (b2) [box=red, below=of a2]        {$B_2$}
(a2.north) edge  node[pos=1,above]{$a$} + (0,5mm)
(a2.south) -- ++ (0,-0.5) node[below] {$\rho$};
\path[draw,->]<5->
node (a3) [box=red, right=of a2]        {$A_3$}
(a2) edge ["$\gamma$"] (a3);
\path[draw,->]<6-> ([xs=-2] a3.north) -- + (0,5mm) node[above]{$a$};
\path[draw,<-]<7-> ([xs=-2] a1.north) -- ++ (0,1)
-| ([xs=2] a3.north) node[pos=0.25] {$\lambda$};
\path[draw,->]<8-> (a0 |- b1) to["$\omega$"] (b1);
\path[draw,->]<9-> (b1.south) -- ++ (0,-0.5) node[below] {$b$};
\path[draw,->]<10-> (b1) edge ["$\alpha$"] (b2);
\path[draw,->]<11-> (a2) edge [dashed,pos=0.25,"$\delta$" '] (b1)
(b2) edge [dashed,pos=0.75,"$\delta$" '] (a1)
(b2.south) -- ++ (0,-0.5) node[below] {$b$};
\end{tikzpicture}
\end{figure}
\end{frame}

\end{document}


Complete image is

and to it is eleven steps. In my MWE in comparison to your I change definition of nodes' style, introduce two new library (positioning and quotas) by which are node positioned and edges labeled respectively.

• It is excellent except I needed the dotted lines($\delta$'s) to appear at the end. Like First row, then second row finally the dotted lines. – marya Jan 20 '17 at 11:40
• I'm sorry, but this is not clear from your question nor now ... anyway, this should not be difficult to you to make necessary changes of cod, isn't it? to further help, please clearly indicate in your question, how many slides has this frame and what is their sequence. maybe with help of my image. – Zarko Jan 20 '17 at 11:49
• @marya, I move dashed line to the last slide in frame. – Zarko Jan 20 '17 at 12:43