2

My preamble is this:

\usepackage{graphicx,tikz}                                          
\usetikzlibrary{matrix,arrows,positioning}                  
\setcounter{MaxMatrixCols}{20}

Currently I am using this:

\begin{tikzpicture}[->,>=stealth',shorten >=1pt,auto,node distance=2.5cm,
thick,main node/.style={square,fill=blue!20,draw,font=\sffamily\Large\bfseries}]
\matrix (m) [matrix of math nodes,nodes={rectangle,draw}, row sep=0.5em,
    minimum size=2em, column sep=0em, text height=1.5ex, text depth=0.25ex]
    { 80 & \cdots & 166 & \quad & 195 & \cdots & 230 \\ };
    \path[->,font=\scriptsize]
    (m-1-1) edge[bend right=80] node[auto] {} (m-1-5)
    (m-1-1) edge[bend right=80] node[auto] {} (m-1-6)
    (m-1-2) edge[bend right=80] node[auto] {} (m-1-5)
    (m-1-2) edge[bend right=80] node[auto] {} (m-1-7)
    (m-1-3) edge[bend right=80] node[auto] {} (m-1-7)
    (m-1-3) edge[bend right=80] node[auto] {} (m-1-5);

    \node[fill=white,minimum size=2.1em] at (-0.025,0) {};

    \path[->,font=\scriptsize]
    (m-1-5) edge[bend right=80] node[auto] {} (m-1-3)
    (m-1-5) edge[bend right=80] node[auto] {} (m-1-2)
    (m-1-6) edge[bend right=80] node[auto] {} (m-1-1)
    (m-1-6) edge[bend right=80] node[auto] {} (m-1-2)
    (m-1-7) edge[bend right=80] node[auto] {} (m-1-3)
    (m-1-7) edge[bend right=80] node[auto] {} (m-1-2);
\end{tikzpicture}

To create:

First off, this is very tedious and I am wondering if there is a better way to create such an image in TeX. In particular, creating the gap in the rectangles required me to put a white square node overtop of an empty node by just guessing at the coordinates. I feel there must be a better way. Also, how would I make one of these nodes filled in yellow? They only way I could figure out how to do that is by overwriting the node with a yellow square node and again guessing at where the coordinates are until it seemed right. Please tell me there is a better way to do this.

Thank you.

  • { 80 & \cdots & 166 & |[draw=none]| \quad & 195 & \cdots & 230 \\ }? For the edges I’d use \path[bend right=80] and then two foreach loops. – Qrrbrbirlbel Jun 15 '15 at 20:58
  • @Qrrbrbirlbel Thanks! |[draw=none]| worked wonders. Any ideas on how to fill a specific node yellow? – Ebearr Jun 15 '15 at 21:11
  • Well, just the same: |[fill=yellow]| at the start of a cell? You can also do stuff like row 1 column 5/.style={nodes={fill=yellow}} or something like that. – Qrrbrbirlbel Jun 15 '15 at 21:13
3

Here's a way without \usetikzlibrary{matrix,arrows,positioning}:

\documentclass[tikz, border=2]{standalone}

\begin{document}
    \begin{tikzpicture}[->,>=stealth,shorten >=1pt,every node/.style={thick,rectangle,draw,minimum width=1cm,minimum height=1cm}]
        \foreach [count=\i] \content/\fill in {80/yellow, \dots/none, 166/blue}
            \node[fill=\fill] at (\i,0) (\i) {\content};
        \foreach [count=\i from 5] \content/\fill in {195/none, \dots/red, 230/green}
            \node[fill=\fill] at (\i,0) (\i) {\content};
        \foreach \first/\second in {1/5,1/6,2/5,2/7,3/7,3/5,5/3,5/2,6/1,6/2,7/3,7/2}
            \draw[->,thick] (\first) edge[bend right=80] (\second);
    \end{tikzpicture}
\end{document}

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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