Graphics, Figures & Tablesproblem with creating flow chart

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
cat123
Posts: 2
Joined: Thu Sep 01, 2016 9:39 pm

problem with creating flow chart

Post by cat123 »

I'm trying to make a flow chart similar / the same as in that PNG image.

I tried with following but it didn't go well :cry:
Can somebody please help me or give me some advice how to begin? Thanks in advance. :)

Code: Select all

\begin{tikzpicture}[node distance=2 cm,auto,>=latex']
    \node [int, pin={[init]above:$\mu$}] (a) {$S$};
    \node (b) [left of=a,node distance=2cm, coordinate] {a};
    \node [int, pin={[init]above:$\mu$}] (c) [right of=a] {$I$};
    \node [coordinate] (end) [right of=c, node distance=2cm]{};
    \path[->] (b) edge node {$a$} (a);
    \path[->] (a) edge node {$v$} (c);
    \draw[->] (c) edge node {$p$} (end) ;
\end{tikzpicture}
Attachments
SIRC.png
SIRC.png (3.7 KiB) Viewed 3856 times
Last edited by Stefan Kottwitz on Thu Sep 08, 2016 1:19 pm, edited 2 times in total.

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

Stefan Kottwitz
Site Admin
Posts: 10345
Joined: Mon Mar 10, 2008 9:44 pm

problem with creating flow chart

Post by Stefan Kottwitz »

Welcome to the forum!

If you would post a Infominimal working example, it would be much easier. The code doesn't contain the styles int and init, so it brings errors.

The drawing is not difficult, I can take a look tomorrow (here it's after midnight), perhaps post the missing styles in the meantime.

Stefan
LaTeX.org admin
User avatar
Stefan Kottwitz
Site Admin
Posts: 10345
Joined: Mon Mar 10, 2008 9:44 pm

problem with creating flow chart

Post by Stefan Kottwitz »

Here is a start. I used a loop with the fancy TikZ syntax for counting and evaluating, to not repeat commands for nodes and edges so much. :-)

Code: Select all

\documentclass[border=80pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows, positioning}
\tikzset{
   rect/.style = { draw, minimum width = 2em, minimum height = 2ex },
  label/.style = { font=\scriptsize },
}
\begin{document}
\begin{tikzpicture}[
    node distance = 1cm, auto, >=latex',
    nodes = { execute at begin node=$,
              execute at end   node=$ },
  ]
  \coordinate (0);
  \foreach \txt/\label [ count=\current,
      evaluate = \current as \previous using int(\current-1) ]
      in {S/\mu,I/\beta,R/\alpha,C/\delta} {
    \node [rect, right = of \previous] (\current) {\txt};
    \draw [->] (\previous) -- node [label] {\label} (\current);
    \draw [->] (\current)  -- node [label] {\mu} ++(0,1);
  }
  \draw [->] (4) to ++(0,-1) -| node [label, near end] {\gamma} (1);
\end{tikzpicture}
\end{document}
flowchart.png
flowchart.png (7.47 KiB) Viewed 3823 times
Stefan
LaTeX.org admin
cat123
Posts: 2
Joined: Thu Sep 01, 2016 9:39 pm

Re: problem with creating flow chart

Post by cat123 »

Thank you very much :))
Post Reply