# Graphs in commutative diagrams in TikZ

I want to draw a diamond shape commutative diagram using tikz. Instead of just letters I want to have simple graphs (just edges and vertices) in the diagram. I tried some stuff but the diagram still looks superugly. Is there any way to make this look smoother?

\documentclass[a4paper,12pt]{article}
\usepackage{tikz}
\usepackage{tikz-cd}
\usetikzlibrary{matrix,arrows}

\begin{document}

\begin{center}
\begin{tikzcd}
&
\begin{tikzpicture}%B
[every node/.style={circle,fill=black,inner sep=3pt}]
\node (a) at (0,0) {};
\node (b) at (0,-1)  {};
\node[olive] (d) at (1,0)  {};
\node[olive] (f) at (0,1)  {};

\foreach \from/\to in {a/b,a/d,a/f}
\draw (\from) -- (\to);
\end{tikzpicture}
\arrow{dr} &\\

\begin{tikzpicture}%A
[every node/.style={circle,fill=black, inner sep=3pt}]
\node (a) at (0,0.5) {};
\node (b) at (0,-0.5)  {};

\foreach \from/\to in {a/b}
\draw (\from) -- (\to);
\end{tikzpicture}
\arrow{ur} \arrow{dr} & &
\begin{tikzpicture}%Amalgam
[every node/.style={circle,fill=black, inner sep=3pt}]
\node (a) at (1,1) {};
\node (b) at (1,0)  {};
\node[orange] (c) at (0.125,0.5) {};
\node[olive] (d) at (2,1)  {};
\node[orange] (e) at (1.7,1.7) {};
\node[olive] (f) at (1,2)  {};

\foreach \from/\to in {a/b, a/c,a/d,a/e,a/f,c/b}
\draw (\from) -- (\to);
\end{tikzpicture}\\
&
\begin{tikzpicture}%C
[every node/.style={circle,fill=black, inner sep=3pt}]
\node (a) at (1,1) {};
\node (b) at (1,0)  {};
\node[orange] (c) at (0.125,0.5) {};
\node[orange] (e) at (1.7,1.7) {};

\foreach \from/\to in {a/b,a/c,a/e,c/b}
\draw (\from) -- (\to);
\end{tikzpicture}
\arrow{ur}
&\\
\end{tikzcd}
\end{center}
\end{document}


-
Welcome to TeX.SX! You can have a look on our starter guide to familiarize yourself further with our format. Could you turn your snippet into a complete minimal working example (MWE)- it really helps that wish to look at your code and help with your problem :) Welcome! – cmhughes Oct 28 '13 at 18:16
This MWE will not compile for me. Are you sure you copied it correctly? – Charles Staats Oct 28 '13 at 18:44
@Charles StaatsI just tried it and it works for me. – Martin B Oct 28 '13 at 19:06
What is the desired output supposed to look like? – Herr K. Oct 28 '13 at 19:49

## Code

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

\begin{document}

\begin{tikzpicture}
[   every node/.style={circle,inner sep=2.5pt,fill=black,outer sep=0pt},
hull/.style={draw=gray!20,fill=none,inner sep=0.6cm},
scale=0.5,
]
%B
\begin{scope}[shift={(30:6)}]
\node (a) at (0,0) {};
\node (b) at (0,-1)  {};
\node[olive] (d) at (1,0)  {};
\node[olive] (f) at (0,1)  {};
\foreach \to in {b,d,f} \draw (a) -- (\to);
\node[hull] (B) at (0,0) {};
\end{scope}
%A
\begin{scope}[shift={(0:0)}]
\node (a) at (0,0) {};
\node (b) at (0,-1)  {};
\draw (a) -- (b);
\node[hull] (A) {};
\end{scope}
%Amalgam
\begin{scope}[shift={(0:{12*cos(30)})}]
\node (a) at (0,0) {};
\node (b) at (0,-1)  {};
\node[orange] (c) at (-0.866,-0.5) {};
\node[olive] (d) at (1,0)  {};
\node[orange] (e) at (0.707,0.707) {};
\node[olive] (f) at (0,1) {};
\foreach \from/\to in {a/b, a/c, a/d, a/e, a/f, c/b} \draw (\from) -- (\to);
\node[hull] (Amalgam) at (0,0) {};
\end{scope}
%C
\begin{scope}[shift={(-30:6)}]
\node (a) at (0,0) {};
\node (b) at (0,-1)  {};
\node[orange] (c) at (-0.866,-0.5) {};
\node[orange] (e) at (0.707,0.707) {};
\foreach \from/\to in {a/b, a/c, a/e, c/b} \draw (\from) -- (\to);
\node[hull] (C) at (0,0) {};
\end{scope}
\foreach \from/\to in {A/B, A/C, B/Amalgam, C/Amalgam} \draw[-latex] (\from) -- (\to);
\end{tikzpicture}

\end{document}


## Output

-

First of all: Nesting TikZ pictures is a bad idea. With a basic TikZ matrix, you could however put a mini-picture consisting of nodes and path in a cell. However, you cannot reference the whole cell.

In this solution a container node style is created that while later serve as the root nodes of our diagram. Each container will use the aac style to use a special setup of the append after command style. The setup is a special local coordinate system which center is at the center of the node and the x and y vectors point to the east and north anchor respectively. This allows the local coordinate system to transform and especially rotate with the root node. We could have also just used the my Size value to setup the coordinate system or used a path picture or …

The settings key contains basic options for our mini-pictures in the containers. Then the three keys base, top and bottom configure the parts of the mini-pictures. These are then used with the aac key to built the mini-picture.

## Code

\documentclass[tikz]{standalone}
\usetikzlibrary{calc,positioning}
\tikzset{aac/.style={
append after command={[shift=(\tikzlastnode.center),
x={($(\tikzlastnode.east)-(\tikzlastnode.center)$)},
y={($(\tikzlastnode.north)-(\tikzlastnode.center)$)}, #1]}}}
\tikzset{
my Size/.initial=+3mm, my distance/.initial=.6,
declare function={my_dist=\pgfkeysvalueof{/tikz/my distance};},
container/.style={shape=circle, draw=gray, inner sep=+0pt, label={#1},
minimum size={8*(\pgfkeysvalueof{/tikz/my Size})}},
settings/.style={every edge/.append style={-},
nodes={draw, fill, shape=circle, inner sep=+0pt,
minimum size=\pgfkeysvalueof{/tikz/my Size}}},
base/.style={insert path={[settings]
node (b1)                  {}
node (b2) at (-90:my_dist) {} edge (b1)}},
top/.style={insert path={
node[olive] (t1) at (90:my_dist) {} edge (b1)
node[olive] (t2) at ( 0:my_dist) {} edge (b1)}},
bottom/.style={insert path={
node[orange] (bo1) at (-90-60:my_dist) {} edge (b1) edge (b2)
node[orange] (bo2) at (    45:my_dist) {} edge (b1)}}}
\begin{document}
\begin{tikzpicture}[thick, node distance=+.25cm and +1.5cm, latex-]
\node[container=base,           aac=base]                         (l) {};
\node[container={base and top}, aac={base,top}, above right=of l] (t) {}  edge (l);
\node[container=below:{base and bottom}, aac={base,bottom}, below right=of l] (b) {}
edge (l);
\node[container=all, aac={base,bottom,top}, below right=of t] {} edge (t) edge (b);
\end{tikzpicture}
\end{document}


## Output

-
I dont know if I already understood how this worked but this looks so much better. thanks! – Martin B Oct 29 '13 at 9:33