2

I'm attempting to create a diagram equivalent to the following using TikZ:

Trajectory in the Muddy Children Problem

I have a solid handle on how to create the individual components/subgraphs in TikZ. Suppose that I have each of them saved in a corresponding file. For example, initial-state.tex looks like the following:

\documentclass[12pt,tikz]{standalone}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{amsthm}
\usepackage{mathtools}
\usepackage[T1]{fontenc}
\usepackage{stix}
\usepackage[english]{babel}
\usepackage[kerning,spacing,babel,final]{microtype}

\usepackage{tikz}
\usetikzlibrary{arrows,positioning,matrix}
\tikzset{
    >=stealth,
    auto,
    font=\scriptsize,
    point/.style={circle,draw,very thick,align=center,
                  anchor=center},
    Point/.style={double,circle,draw,very thick,align=center,
                  anchor=center},
    transform shape,
}

\begin{document}

\begin{tikzpicture}
    \centering
    \matrix (m) [matrix of nodes, row sep=0.5cm,column sep=1.25cm] {
        &
        \node (1) [point] {$AB$};
        & &
        \node (2) [point] {$B$}; \\
        \node (3) [Point] {$ABC$};
        & &
        \node (4) [point] {$BC$};
        & \\ &
        \node (5) [point] {$A$};
        & &
        \node (6) [point] {}; \\
        \node (7) [point] {$AC$};
        & &
        \node (8) [point] {$C$};
        & \\
    };
    \path[solid]
        (1) edge [loop above,very thick] (1)
        (2) edge [loop above,very thick] (2)
        (3) edge [loop above,very thick] (3)
        (4) edge [loop above,very thick] (4)
        (5) edge [loop below,very thick] (5)
        (6) edge [loop below,very thick] (6)
        (7) edge [loop below,very thick] (7)
        (8) edge [loop below,very thick] (8)
        (1) [<->,very thick] edge node[above right, pos=0.75,
            minimum size=0pt] {$A$} (2)
        (1) [<->,very thick] edge node[above, minimum size=0pt] {$C$} (3)
        (2) [<->,very thick] edge node[above, minimum size=0pt] {$C$} (4)
        (2) [<->,very thick] edge node[above left, pos=0.4,
            minimum size=0pt] {$B$} (6)
        (3) [<->,very thick] edge node[above right, pos=0.75,
            minimum size=0pt] {$A$} (4)
        (3) [<->,very thick] edge node[above left, pos=0.4,
            minimum size=0pt] {$B$} (7)
        (4) [<->,very thick] edge node[above left, pos=0.4,
            minimum size=0pt] {$B$} (8)
        (6) [<->,very thick] edge node[above, minimum size=0pt] {$C$} (8)
        (7) [<->,very thick] edge node[above right, pos=0.75,
            minimum size=0pt] {$A$} (8)
        ;
    \path[dotted]
        (1) [<->,very thick] edge node[above left, pos=0.4,
            minimum size=0pt] {$B$} (5)
        (5) [<->,very thick] edge node[above right, pos=0.75,
            minimum size=0pt] {$A$} (6)
        (5) [<->,very thick] edge node[above, minimum size=0pt] {$C$} (7)
        ;
\end{tikzpicture}

\end{document}

And similarly for the other subgraphs in the diagram. How can I draw the larger figure? Specifically:

  • How can I position the edge between the two larger subgraphs?
  • How can I have two labels positioned along the edge: one being a graph itself, and the other being a simple text label as shown in the attached figure?

I've tried reading the TikZ documentation but wasn't able to find how to position nodes along an edge as in the example. I can do this with another such as OmniGraffle fairy easily, but if I could do all of this within TikZ I'd prefer that.

1

I would place both \matrixes in the same tikzpicture, named m and m2, and then you can easily draw the connecting arrow with \draw [->] (m) -- (m2);.

You can place multiple nodes along a path. For example,

\draw (a) -- (b)
   node[above,midway] {foo}
   node[below,midway] {bar};

In the code below that is the basic principle used.

I also suggested a different way of drawing the connections in each matrix, using loops. Use or ignore this as you see fit.

You had also specified matrix of nodes (which I changed to matrix of math nodes), but you didn't make use of it. With that option, and nodes={point} to set the general style for the nodes, you can write just A in a cell, instead of \node [point] {A};. Such nodes are named automatically as <matrix name>-<row number>-<column number>, e.g. m-3-2.

output of code

\documentclass[12pt,tikz]{standalone}
%\usepackage{amsmath} %loaded by mathtools
\usepackage{amssymb}
\usepackage{amsthm}
\usepackage{mathtools}
\usepackage[T1]{fontenc}
\usepackage{stix}
\usepackage[english]{babel}
\usepackage[kerning,spacing,babel,final]{microtype}

\usepackage{tikz}
\usetikzlibrary{arrows,positioning,matrix}
\tikzset{
    >=stealth,
    auto,
    font=\scriptsize,
    point/.style={circle,draw,very thick,align=center,
                  anchor=center},
    Point/.style={double,circle,draw,very thick,align=center,
                  anchor=center},
    transform shape,
}

\begin{document}

\begin{tikzpicture}

   % left matrix
    \matrix (m) [matrix of math nodes, nodes={point}, row sep=0.5cm,column sep=1.25cm] {
                     & AB &    & B  \\
        |[Point]|ABC &    & BC &    \\
                     &  A &    & {} \\
                  AC &    &  C &    \\
    };

    % right matrix
    \matrix (m2) [right=6cm of m, matrix of math nodes, nodes={point}, row sep=0.5cm,column sep=1.25cm] {
                     & AB &    & B  \\
        |[Point]|ABC &    & BC &    \\
                     &  A &    &    \\
                  AC &    &  C &    \\
    };


% draw the lines that only occur in the left matrix
\draw
     (m-3-4) edge [loop below,very thick] (m-3-4)
     (m-1-4) [<->,very thick] edge node[above left, pos=0.4,
           minimum size=0pt] {$B$} (m-3-4)
     (m-3-4) [<->,very thick] edge node[above, minimum size=0pt] {$C$} (m-4-3);
\draw[dotted]
     (m-3-2) [<->,very thick] edge node[above right, pos=0.75,
            minimum size=0pt] {$A$} (m-3-4);

% draw the lines that occur in both
\foreach \MAT in {m,m2}
{
  \foreach \cell in {1-2,1-4,2-1,2-3}
     \draw (\MAT-\cell) edge [loop above,very thick] (\MAT-\cell);

  \foreach \cell in {3-2,4-1,4-3}
     \draw (\MAT-\cell) edge [loop below,very thick] (\MAT-\cell);

  \draw
        (\MAT-1-2) [<->,very thick] edge node[above right, pos=0.75,
            minimum size=0pt] {$A$} (\MAT-1-4)
        (\MAT-1-2) [<->,very thick] edge node[above, minimum size=0pt] {$C$} (\MAT-2-1)
        (\MAT-1-4) [<->,very thick] edge node[above, minimum size=0pt] {$C$} (\MAT-2-3)
        (\MAT-2-1) [<->,very thick] edge node[above right, pos=0.75,
            minimum size=0pt] {$A$} (\MAT-2-3)
        (\MAT-2-1) [<->,very thick] edge node[above left, pos=0.4,
            minimum size=0pt] {$B$} (\MAT-4-1)
        (\MAT-2-3) [<->,very thick] edge node[above left, pos=0.4,
            minimum size=0pt] {$B$} (\MAT-4-3)
        (\MAT-4-1) [<->,very thick] edge node[above right, pos=0.75,
            minimum size=0pt] {$A$} (\MAT-4-3)
        ;
    \draw[dotted]
        (\MAT-1-2) [<->,very thick] edge node[above left, pos=0.4,
            minimum size=0pt] {$B$} (\MAT-3-2)
        (\MAT-3-2) [<->,very thick] edge node[above, minimum size=0pt] {$C$} (\MAT-4-1)
        ;
}


% connecting arrow
\draw [-stealth,shorten <=10mm,shorten >=10mm,ultra thick] (m) -- (m2)
  node[midway,below] {declare}
  node[midway,above=1cm,draw,rounded corners,ultra thick,align=center,label=below:$c_p$] (x) 
      { $p : \varphi$ \\ $ s : c$ };

% loop above node
\draw (x) edge [loop above,very thick] node[above]{$A,B,C$} (x);
\end{tikzpicture}

\end{document}

Your Answer

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