[Tex/LaTex] What are some good examples of LaTeX Cayley diagrams

best practicesdiagramsexamples

I'm looking for some good examples of LaTeX code used to generate basic Cayley diagrams like this one:

D4 Group Diagram

Ideally, I'd like for the examples to make it fairly clear how to modify or remove various elements of the graph (labels, colors, line styles, etc.), and how to produce graphs for different basic groups.

Best Answer

TikZ should be pretty useful doing this. It's a package to 'draw' stuff in latex. I tried replicating your picture, there are still some rough edges, but it looks pretty nice I think.

\documentclass{article}
\usepackage{tikz}

\begin{document}
\usetikzlibrary{arrows,positioning}
\begin{tikzpicture} [%
    nd/.style = {circle,fill=black,text=white,inner sep=1pt},
    tn/.style = {node distance=1pt},
    redarrow/.style={->, red, fill=none,>=stealth},
    blueline/.style={-,blue,fill=none}]

    \node[nd] (otl) at (0,0) {\sffamily F};
    \node[nd] (itl) [below right=of otl] {\sffamily F};
    \node[nd] (itr) [right=of itl] {\sffamily F};
    \node[nd] (otr) [above right=of itr] {\sffamily F};
    \node[nd] (ibl) [below=of itl] {\sffamily F};
    \node[nd] (obl) [below left=of ibl] {\sffamily F};
    \node[nd] (ibr) [right=of ibl] {\sffamily F};
    \node[nd] (obr) [below right=of ibr] {\sffamily F};

    \draw[redarrow] (otr) -- (otl);
    \draw[redarrow] (otl) -- (obl);
    \draw[redarrow] (obl) -- (obr);
    \draw[redarrow] (obr) -- (otr); 
    \draw[redarrow] (itl) -- (itr);
    \draw[redarrow] (itr) -- (ibr);
    \draw[redarrow] (ibr) -- (ibl);
    \draw[redarrow] (ibl) -- (itl); 

    \draw[blueline] (ibl) -- (obl);
    \draw[blueline] (itl) -- (otl);
    \draw[blueline] (ibr) -- (obr);
    \draw[blueline] (itr) -- (otr);

    \node[tn] [below right=of itl] {\tiny{$a$}};
    \node[tn] [below left=of itr] {\tiny{$a^2$}};
    \node[tn] [above left=of ibr] {\tiny{$a^3$}};
    \node[tn] [above right=of ibl] {\tiny{$e$}};

    \node[tn] [below left=of obl] {\tiny{$b$}};
    \node[tn] [below=of obr] {\tiny{$ab=ba^3$}};
    \node[tn] [above=of otl] {\tiny{$ba=a^3b$}};
    \node[tn] [above=of otr] {\tiny{$a^2b=ba^2$}};

\end{tikzpicture}
\end{document}

which looks like

screenshot of the diagram

I would normally name the styles according to their uses, but since I have no idea what the diagram represents, I just named them according to their styles. The rotation is still missing, I'm trying to get that right though ;)

EDIT:

I got rotation etc. to work. Since the syntax is a little bit harder to read, I thought I would define a command for the nodes in the graph. I also fixed the text height for the 'captions', so that the ugly offset of the text is now gone. It's just the upper part that's changed, but in spirit of providing a MWE I also copied the rest of the code again:

\documentclass{article}
\usepackage{tikz}

\begin{document}
\usetikzlibrary{arrows,positioning}

\newcommand{\nd}[4]{\node[nd] (#1) #2 [label={[white,rotate=#3]center:{\sffamily #4}}] {}};

\begin{tikzpicture} [%
    nd/.style = {circle,fill=black,text=white,inner sep=4pt},
    tn/.style = {node distance=1pt,text height=0.5ex},
    redarrow/.style={->, red, fill=none,>=stealth},
    blueline/.style={-,blue,fill=none}]

    \nd{otl}{at (0,0)}{0}{F};
    \nd{itl}{[below right=of otl]}{270}{F};
    \nd{itr}{[right=of itl]}{0}{F};
    \nd{otr}{[above right=of itr]}{90}{x};
    \nd{ibl}{[below=of itl]}{90}{F};
    \nd{obl}{[below left=of ibl]}{0}{e};
    \nd{ibr}{[right=of ibl]}{180}{F};
    \nd{obr}{[below right=of ibr]}{90}{F};

    \draw[redarrow] (otr) -- (otl);
    \draw[redarrow] (otl) -- (obl);
    \draw[redarrow] (obl) -- (obr);
    \draw[redarrow] (obr) -- (otr); 
    \draw[redarrow] (itl) -- (itr);
    \draw[redarrow] (itr) -- (ibr);
    \draw[redarrow] (ibr) -- (ibl);
    \draw[redarrow] (ibl) -- (itl); 

    \draw[blueline] (ibl) -- (obl);
    \draw[blueline] (itl) -- (otl);
    \draw[blueline] (ibr) -- (obr);
    \draw[blueline] (itr) -- (otr);

    \node[tn] [below right=of itl] {\tiny{$a$}};
    \node[tn] [below left=of itr] {\tiny{$a^2$}};
    \node[tn] [above left=of ibr] {\tiny{$a^3$}};
    \node[tn] [above right=of ibl] {\tiny{$e$}};

    \node[tn] [below left=of obl] {\tiny{$b$}};
    \node[tn] [below=of obr] {\tiny{$ab=ba^3$}};
    \node[tn] [above=of otl] {\tiny{$ba=a^3b$}};
    \node[tn] [above=of otr] {\tiny{$a^2b=ba^2$}};

\end{tikzpicture}
\end{document}

better version of the diagram