1

I would like to replicate the following image for my work:

enter image description here

I now have the following MWE:

\documentclass[12pt]{article}
\usepackage[margin=2cm]{geometry}
\usepackage [english]{babel}
\usepackage{amsmath, amssymb}
\usepackage{tikz}
\usetikzlibrary{positioning}
\usetikzlibrary{arrows}
\usetikzlibrary{shapes.multipart}
\begin{document}
\begin{center}
\begin{tikzpicture}[sharp corners=2pt,inner sep=7pt,node distance=.8cm,every text node part/.style={align=center}]

% Draw rectangular nodes (switch sharp to smooth for different corners)
\node[draw, minimum height = 1cm, minimum width = 3cm] (healthy){healthy $(h)$};
\node[draw,below = 1.5cm of healthy, minimum height = 1cm, minimum width = 3cm](dead){dead $(d)$};
\node[draw,right=3cm of healthy, minimum height = 1cm, minimum width = 3cm](sick){sick $(s)$};

\end{tikzpicture}\end{center}
\end{document}

enter image description here

Is there any way I can horizontally center the "dead (d)" node (as in the image)?

2
  • You can find explanations of any options in the package manual. It's a big manual, but just search for the option in question; clicking on it will jump to its main explanation inside the manual. For instance -triangle 60 is an arrow tip specification and inner sep=7pt adjusts the padding between the text in the boxes and the drawn rectangle shape. Jul 24, 2014 at 15:40
  • Please see the update. Jul 24, 2014 at 16:12

2 Answers 2

2

One way to do this is with the calc TikZ library.

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{calc}
\usetikzlibrary{positioning}
\usetikzlibrary{arrows}
\begin{document}
\begin{tikzpicture}[
    sharp corners=2pt,
    inner sep=7pt,
    node distance=3cm,
    >=latex]
\tikzstyle{my node}=[draw,minimum height=1cm,minimum width=3cm]
\node[my node] (healthy){healthy $(h)$};
\node[my node,right=of healthy](sick){sick $(s)$};
\node[my node] at ($(healthy)!0.5!(sick)-(0pt,1.5cm)$) (dead) {dead $(d)$};
\draw[->] (healthy) -- (dead);
\draw[->] (sick) -- (dead);
\draw[->] (healthy.5) -- (sick.175);
\draw[<-] (healthy.355) -- (sick.185);
\end{tikzpicture}
\end{document}

sample code output

The key bit is the ($(healthy)!0.5!(sick)-(0pt,1.5cm)$) coordinate specification. It first finds the midpoint between the healthy and sick nodes, then moves down by 1.5cm.

The arrows from healthy and sick to dead are pretty straightforward. TikZ places them along the lines connecting the centers, but starting and ending at the edges of the nodes.

Drawing the double arrows is a bit more complicated. The (healthy.5) coordinate is at the intersection of the outer edge of the healthy node and a ray making an angle of 5 degrees from the center of that node. Same for (sick.175). Since both nodes have the same width, rotating up 5 degrees is the same for both nodes. The result is a line from center to center nudged up by a bit. Same for the arrow from (healthy.355) to (sick.185).

3
  • Much, much cleaner than what I have. Thank you! Jul 24, 2014 at 17:39
  • By the way, what does >=latex mean? Jul 24, 2014 at 17:40
  • @Clarinetist: > is a key to set the arrowhead on the far end of the line segment. There are several possible values, and latex gets you the filled triangular arrowheads like you see above. There are plenty of other choices; see the “Arrow Tip Library” section of the PGF/TikZ manual. Jul 24, 2014 at 19:38
2

xshift was the key option that I did not know about. MWE:

\documentclass[12pt]{article}
\usepackage[margin=2cm]{geometry}
\usepackage [english]{babel}
\usepackage{amsmath, amssymb}
\usepackage{tikz}
\usetikzlibrary{positioning}
\usetikzlibrary{arrows}
\usetikzlibrary{shapes.multipart}
\begin{document}
\begin{center}
%\begin{tikzpicture}[every text node part/.style={align=center}] used for multiple parts,
%along with shapes.multipart tikz library.
\begin{tikzpicture}[sharp corners=2pt,inner sep=7pt,node distance=.8cm,every text node part/.style={align=center}]

% Draw rectangular nodes (switch sharp to smooth for different corners)
\node[draw, minimum height = 1cm, minimum width = 3cm] (healthy){healthy $(h)$};
\node[draw,below = 1.5cm of healthy, xshift = 3cm, minimum height = 1cm, minimum width = 3cm](dead){dead $(d)$};
\node[draw,right=3cm of healthy,  minimum height = 1cm, minimum width = 3cm](sick){sick $(s)$};
\end{tikzpicture}\end{center}
\end{document}

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .