Graphics, Figures & TablesBoxes and Arrows

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
clarinetist
Posts: 11
Joined: Sun Nov 18, 2012 8:20 pm

Boxes and Arrows

Post by clarinetist »

How would this be done in LaTeX? (Arrows are supposed to be straight.)
Capture.PNG
Capture.PNG (10.76 KiB) Viewed 17242 times

Recommended reading 2024:

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

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

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Boxes and Arrows

Post by localghost »

clarinetist wrote:How would this be done in LaTeX? […]
Two possible packages.
With this information you can start on your own and present code for corrections if necessary.


Thorsten
clarinetist
Posts: 11
Joined: Sun Nov 18, 2012 8:20 pm

Boxes and Arrows

Post by clarinetist »

Here's what I've got.

Code: Select all

\documentclass[12pt]{article}
\usepackage[margin=2cm]{geometry}
\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 = 4cm, minimum width = 4cm] (state0){\textbf{0} \\ \\
$(x)$ and $(y)$ \\ both alive};
\node[draw,below=2cm of state0, minimum height = 4cm, minimum width = 4cm](state2){\textbf{2} \\ \\
Only $(y)$ is alive};
\node[draw,right=2cm of state0, minimum height = 4cm, minimum width = 4cm](state1){\textbf{1} \\ \\ 
Only $(x)$ is alive};
\node[draw,below=2cm of state1, minimum height = 4cm, minimum width = 4cm](state3){\textbf{3} \\ \\
$(x)$ and $(y)$ \\  both dead};

%Draw arrows
\draw[-triangle 60] (state0) -- (state2) node [midway, above, left = 0.1cm]{$\mu^{02}_{x+t:y+t}$};
\draw[-triangle 60] (state0) -- (state1) node [midway, above]{$\mu^{01}_{x+t:y+t}$};
\draw[-triangle 60] (state1) -- (state3) node [midway, above, right = 0.1cm]{$\mu^{13}_{x+t:y+t}$};
\draw[-triangle 60] (state2) -- (state3) node [midway, above]{$\mu^{23}_{x+t:y+t}$};
\draw[-triangle 60] (state0) -- (state3) node [midway, above, rotate = -45]{$\mu^{03}_{x+t:y+t}$};
\end{tikzpicture}
\end{center}
\end{document}
Is there any way I can guarantee that the shapes are squares with some length and width? (i.e., can I control the length and width of the squares without "minimum height" and "minimum width"?)
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Boxes and Arrows

Post by localghost »

clarinetist wrote:[…] Is there any way I can guarantee that the shapes are squares with some length and width? (i.e., can I control the length and width of the squares without "minimum height" and "minimum width"?)
Yes. And you already do so successfully. Hence I don't see the problem. What exactly is the questions here?
clarinetist
Posts: 11
Joined: Sun Nov 18, 2012 8:20 pm

Boxes and Arrows

Post by clarinetist »

What I mean is, is there a way for me to specify the dimensions of the nodes without the "minimum" parameters? For example, if I switched the dimensions to 3cm (code is below), the squares are no longer the same size.

Code: Select all

\documentclass[12pt]{article}
\usepackage[margin=2cm]{geometry}
\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 = 3cm, minimum width = 3cm] (state0){\textbf{0} \\ \\
$(x)$ and $(y)$ \\ both alive};
\node[draw,below=2cm of state0, minimum height = 3cm, minimum width = 3cm](state2){\textbf{2} \\ \\
Only $(y)$ is alive};
\node[draw,right=2cm of state0, minimum height = 3cm, minimum width = 3cm](state1){\textbf{1} \\ \\ 
Only $(x)$ is alive};
\node[draw,below=2cm of state1, minimum height = 3cm, minimum width = 3cm](state3){\textbf{3} \\ \\
$(x)$ and $(y)$ \\  both dead};

%Draw arrows
\draw[-triangle 60] (state0) -- (state2) node [midway, above, left = 0.1cm]{$\mu^{02}_{x+t:y+t}$};
\draw[-triangle 60] (state0) -- (state1) node [midway, above]{$\mu^{01}_{x+t:y+t}$};
\draw[-triangle 60] (state1) -- (state3) node [midway, above, right = 0.1cm]{$\mu^{13}_{x+t:y+t}$};
\draw[-triangle 60] (state2) -- (state3) node [midway, above]{$\mu^{23}_{x+t:y+t}$};
\draw[-triangle 60] (state0) -- (state3) node [midway, above, rotate = -45]{$\mu^{03}_{x+t:y+t}$};
\end{tikzpicture}
\end{center}
\end{document}
I think the 4cm minimum is perhaps a bit too big for the page I'm putting it in. Is it because the text will not fit in the node?
User avatar
localghost
Site Moderator
Posts: 9202
Joined: Fri Feb 02, 2007 12:06 pm

Boxes and Arrows

Post by localghost »

clarinetist wrote:What I mean is, is there a way for me to specify the dimensions of the nodes without the "minimum" parameters? For example, if I switched the dimensions to 3cm (code is below), the squares are no longer the same size. […]
The size of a node primarily orientates itself towards the size of its content. If the content is small, the minimum size specifications are active (by the keys minimum size, minimum width, minimum height). If the content is bigger than the specified minimum dimensions, the concerned node will grow and so it can happen that nodes have different sizes.
clarinetist
Posts: 11
Joined: Sun Nov 18, 2012 8:20 pm

Boxes and Arrows

Post by clarinetist »

localghost wrote:The size of a node primarily orientates itself towards the size of its content. If the content is small, the minimum size specifications are active (by the keys minimum size, minimum width, minimum height). If the content is bigger than the specified minimum dimensions, the concerned node will grow and so it can happen that nodes have different sizes.
Thank you for your help! :)
Post Reply