Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I'd like make something like the pic below, but in horizontal format. How do I get the text boxes equidistant between susceptible and exposed? Relative positioning of nodes in TikZ uses coordinates. Isn't there a way to do with relative to an object?

enter image description here

   \documentclass{article}

%\usepackage[latin1]{inputenc}
\usepackage{tikz}
\usetikzlibrary{shapes,arrows}
\usetikzlibrary{calc,
arrows,decorations.pathmorphing,
backgrounds,fit,positioning,shapes.symbols,chains}
\usetikzlibrary{decorations.pathreplacing}


\begin{document}



% Define block styles
\tikzstyle{block} = [rectangle, draw, fill=blue!30,
    text width=5em, text centered, rounded corners, minimum height=4em]
\tikzstyle{line} = [draw, -latex']
%\tikzstyle{curve}=[draw,(latex']


\begin{figure}[!ht]
\centering\makebox[\textwidth]{
\begin{tikzpicture}[node distance =4cm, auto,
comment/.style={
rectangle, 
inner sep= 5pt, 
text width=4cm, }]


    % Place nodes
    \node [block] (susceptible) {Susceptible};
    \node [block, right of=susceptible] (exposed) {Exposed};


\draw [decorate,decoration={brace,amplitude=10pt},xshift=0pt,yshift=0pt]
 (3.8,-2)--(-1,-2)  node [black,midway,yshift=-0.6cm] 
{ \emph{Environmental \& Human factors} 
};


    \node [block, right of=exposed] (infectious) {Infectious};

\draw [decorate,decoration={brace,amplitude=10pt},xshift=0pt,yshift=0pt]
(7.9,-2) -- (4.1,-2)  node [black,midway,yshift=-0.6cm] 
{ \emph{Variable immunity} };




   \node [block, right of=infectious] (removed) {Removed};
\draw [decorate,decoration={brace,amplitude=10pt},xshift=0pt,yshift=0pt]
(12,-2) -- (8.2,-2)  node [black,midway,yshift=-0.6cm] 
{ \emph{Control parameters} };


\draw [decorate,decoration={brace,amplitude=10pt},xshift=0pt,yshift=0pt]
(0.1,1) -- (3.9,1) node [black,midway,yshift=0.6cm] 
{\large  Contact parameters};

\draw [decorate,decoration={brace,amplitude=10pt},xshift=0pt,yshift=0pt]
(4.1,1) -- (12,1) node [black,midway,yshift=0.6cm] 
{\large  Disease parameters};


    \path [line] (susceptible) -- (exposed);
    \path [line] (exposed) -- (infectious);
    \path [line] (infectious) -- (removed);

\path[line,dashed] (removed.south) -- + (0,-.35) -- + (-12,-.35) -- (susceptible.south);


\end{tikzpicture}}
\smallskip
\label{fig:flowchart_disease_transmission}
\caption{Flowchart of fundamental disease transmission mechanisms}
\end{figure}


\end{document}

EDIT Looks like this and took me 2 hours (looks okay-ish):

enter image description here In powerpoint, 5 mins but looks pants!

Still can't work out how to get an itemized list in the lower braces.

share|improve this question
1  
Look pgf/tikz manual for "chains" examples. Also here –  JLDiaz Mar 20 '13 at 16:36
    
Is it not possible without chains? –  HCAI Mar 20 '13 at 16:42

2 Answers 2

up vote 6 down vote accepted

You were almost there! I just want to suggest some changes to your code.

Don't use fixed coordinates if you can use relative ones. As an example, you say

\path[line,dashed] (removed.south) -- + (0,-.35) -- + (-12,-.35) -- (susceptible.south);

because you know distance between removed and susceptible nodes, but if you change node distance will have to also modify this line (and all braces). It's better to use

\draw [line,dashed] (removed.south) -- ++ (0,-.35) -| (susceptible.south);

which means, "draw a dashed line from removed.south to a point .35cm below it, move there and draw a rectangular corner from this point to susceptible.south".

For all your braces you can use something like:

\draw [decorate,decoration={brace,amplitude=10pt,raise=3mm}]
    (susceptible.85) -- (exposed.95) 
    node [black,midway,yshift=6mm] {\large  Contact parameters};

raise option moves brace up from reference points which are now susceptible.85 and exposed.95. This means a point on nodes border at angle 85.

For braces below blocks you can use mirror option and you won't have to change nodes order.

\draw [decorate,decoration={brace,amplitude=10pt,raise=6mm, mirror}]
      (susceptible.275)--(exposed.265)  
      node  [black,midway,yshift=-1cm,text width=3cm, align=center,anchor=north] (EHF)
     {\emph{Environmental \\ \& Human factors}};

From previous line, you can see I've splitted headers form lists. May be it's not too much nice but it can help to place them.

Text in nodes is something like a parbox if you fix some text width, so you can use itemized lists, or just set an alignment option. You will find two examples in next code.

\documentclass{article}    
\usepackage{tikz}
\usetikzlibrary{shapes,arrows}
\usetikzlibrary{calc,
arrows,decorations.pathmorphing,
backgrounds,fit,positioning,shapes.symbols,chains}
\usetikzlibrary{decorations.pathreplacing}

\begin{document}

% Define block styles
\tikzstyle{block} = [rectangle, draw, fill=blue!30,
    text width=5em, text centered, rounded corners, minimum height=4em]
\tikzstyle{line} = [draw, -latex']

\begin{figure}[!ht]
\centering\makebox[\textwidth]{
\begin{tikzpicture}[node distance =4cm, auto,
comment/.style={
rectangle, 
inner sep= 5pt, 
text width=4cm, }]

    % Place nodes
    \node [block] (susceptible) {Susceptible};
    \node [block, right of=susceptible] (exposed) {Exposed};
    \node [block, right of=exposed] (infectious) {Infectious};
    \node [block, right of=infectious] (removed) {Removed};

    \draw [line] (susceptible) -- (exposed);
    \draw [line] (exposed) -- (infectious);
    \draw [line] (infectious) -- (removed);

     \draw [line,dashed] (removed.south) -- ++ (0,-.35) -| (susceptible.south);

\draw [decorate,decoration={brace,amplitude=10pt,raise=3mm}]
(susceptible.85) -- (exposed.95) node [black,midway,yshift=6mm] 
{\large  Contact parameters};

\draw [decorate,decoration={brace,amplitude=10pt,raise=3mm},xshift=0pt,yshift=0pt]
(exposed.85) -- (removed.95) node [black,midway,yshift=6mm] 
{\large  Disease parameters};


\draw [decorate,decoration={brace,amplitude=10pt,raise=6mm, mirror}]
 (susceptible.275)--(exposed.265)  node  [black,midway,yshift=-1cm,text width=3cm, align=center,anchor=north] (EHF)
{ \emph{Environmental \\\& Human factors} 
};

\draw [decorate,decoration={brace,amplitude=10pt,raise=6mm, mirror}]
(exposed.275) -- (infectious.265)  node (VI) [black,midway,yshift=-1.5cm] 
{ \emph{Variable immunity} };

\draw [decorate,decoration={brace,amplitude=10pt,raise=6mm, mirror}]
(infectious.275) -- (removed.265) node (CP) [black,midway,yshift=-1.5cm] 
{ \emph{Control parameters} };

\node [text width=4.5cm, align=left, anchor=north, below=1mm of EHF] {Bioaerosol load\\
Surface pathogen loading\\
Surface contact probability}; 

\node [text width=3.5cm, align=left, anchor=north, below=1mm of CP] {\begin{itemize}
\item Detection
\item Quarantine\end{itemize}}; 

\end{tikzpicture}}
\smallskip
\label{fig:flowchart_disease_transmission}
\caption{Flowchart of fundamental disease transmission mechanisms}
\end{figure}

\end{document}

The final result is:

enter image description here

share|improve this answer
    
Just exactly what I was looking for! Thank you so much for explaining the different options too! Very helpful! How long did you take to learn tikz? A flowchart and this picture took me 6 hours today... And that's 6 hours not writing my phd! –  HCAI Mar 20 '13 at 18:14
    
Out of curiosity if I wanted to make a curve or arc between removedand susceptible instead of the dotted line, is it a simple operation or would I have to define angles and coordinates etc? –  HCAI Mar 20 '13 at 18:18
1  
@user1134241 [rounded corners] would not be enough? Or replace -- by to[bend left] –  JLDiaz Mar 20 '13 at 18:27
    
@user1134241 as JLDiaz suggested to[bend left] is the easiest option. You can even fix bending angle with to[bend left=10]. –  Ignasi Mar 21 '13 at 8:37
    
@user1134241 Every day I learn something new about TikZ. I think you should read tutorials chapters from TikZ's manual. They provide a lot of information in an instructive and funny style. –  Ignasi Mar 21 '13 at 8:44

I cleaned a bit your code by using styles. Also used the anchors of the boxes to position the braces, instead of absolute coordinates. Also, introduced the option text width for the bottom labels, and this allows you to use imtemize in their contents:

\usetikzlibrary{decorations.pathreplacing,positioning,arrows}

% Define some styles
\tikzset{
 block/.style = {
    rectangle, draw, fill=blue!30,
    text width=5em, 
    text centered, 
    rounded corners, 
    minimum height=4em},
 line/.style = {
    draw, -latex'},
 my brace/.style = {
   decorate,decoration={brace,amplitude=10pt},
   shorten >=3pt, shorten <=3pt
 },
 bottom label/.style = {
    black, midway, yshift=-3ex, font=\itshape,
    text width = 3cm, text centered,
 },
 top label/.style = {
    black, midway, above, yshift=3ex, font=\large,
 },
}

\begin{figure}[!ht]
\centering\makebox[\textwidth]{
\begin{tikzpicture}[node distance =4cm, auto]

    % Place nodes
    \node [block]                       (susceptible) {Susceptible};
    \node [block, right of=susceptible] (exposed)     {Exposed};
    \node [block, right of=exposed]     (infectious)  {Infectious};
    \node [block, right of=infectious]  (removed)     {Removed};

\coordinate[below=8mm of susceptible] (bottom brace);

\draw [my brace]
      (exposed.south|-bottom brace) -- (susceptible.south west|-bottom brace) 
      node[bottom label] {
        Environmental \& Human factors
        \begin{itemize}
        \item Foo
        \item Bar
        \item Foobar
        \end{itemize}
      };

\draw [my brace]
    (infectious.south|-bottom brace) -- (exposed.south|-bottom brace)
    node [bottom label] { Variable immunity };

\draw [my brace]
    (removed.south east|-bottom brace) -- (infectious.south|-bottom brace)
    node [bottom label] { 
      Control parameters 
        \begin{itemize}
        \item Foo
        \item Bar
        \end{itemize}
     };    

\coordinate[above=3mm of susceptible] (top brace);

\draw [my brace] 
    (susceptible.north|-top brace) -- (exposed.north|-top brace)
    node [top label] {Contact parameters};

\draw [my brace]
    (exposed.north|-top brace) -- (removed.north|-top brace)
    node[top label] {Disease parameters};

\draw[line] (susceptible) -- (exposed)
            (exposed) -- (infectious)
            (infectious) -- (removed);

\path[line,dashed] 
   (removed.south) -- +(0,-.35) -| (susceptible.south);

\end{tikzpicture}}
\smallskip
\label{fig:flowchart_disease_transmission}
\caption{Flowchart of fundamental disease transmission mechanisms}
\end{figure}

Result

share|improve this answer
    
Looks fantastic! Thank you very very much! –  HCAI Mar 20 '13 at 18:12

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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