3

I need to draw a Cayley graph, but I dont know how to do it. In particular i need the same graph as shown in the figure. Please help me.enter image description here

I can do this for now:

\documentclass[tikz,border=5]{standalone}
\usetikzlibrary{lindenmayersystems}
\pgfdeclarelindenmayersystem{cayley}{
  \rule{F -> F [ R [F] [+F] [-F] ]}
  \symbol{R}{
    \pgflsystemstep=0.5\pgflsystemstep
  } 
}
\begin{document}
\begin{tikzpicture}
\draw l-system [l-system={cayley, axiom=[F] [+F] [-F] [++F], step=5cm, order=6}];
\end{tikzpicture}
\end{document}


\begin{document}
\begin{tikzpicture}
\draw l-system [l-system={cayley, axiom=[A] [+A] [-A] [++A], step=5cm, order=4}];
\end{tikzpicture}
\end{document}
2
  • 1
    Welcome to TeX.SE. Unfortunately, we really frown on "Please do this for me" type questions - they make it difficult to create lasting value for yourself and others. Have you made an attempt at creating the graph, and it doesn't quite look right? The code for that would be a great thing to edit into your post. (But if you just need a graphic that looks exactly that your included image, why not \includegraphics?)
    – Teepeemm
    Oct 11, 2019 at 13:10
  • This code seems to be literally copied from tex.stackexchange.com/a/223078.
    – user194703
    Oct 11, 2019 at 22:44

2 Answers 2

6

This uses a local coordinate system that has the dimensions of the Cayley graph to annotate it. And then there is some mechanism that prints the group element depending on the location in the graph, such that one can use foreach loops. This mechanism is not necessarily good for going to higher order.

\documentclass[tikz,border=5]{standalone}
\usetikzlibrary{lindenmayersystems,calc}
\pgfdeclarelindenmayersystem{cayley}{% https://tex.stackexchange.com/a/223078
  \rule{F -> F [ R [F] [+F] [-F] ]}
  \symbol{R}{
    \pgflsystemstep=0.5\pgflsystemstep
  } 
}
\newcommand\mysymb[1]{\pgfmathtruncatemacro{\itest}{Mod(#1,8)}%
\ifcase\itest
\sigma%
\or
\tau%
\or
\sigma^{-1}%
\or
\tau^{-1}%
\or
\sigma^2%
\or
\tau^2%
\or
\sigma^{-2}%
\or
\tau^{-2}%
\fi}
\begin{document}
\begin{tikzpicture}
 \draw l-system 
 [l-system={cayley, axiom=[F] [+F] [-F] [++F], step=5cm, order=6}];
 \begin{scope}[shift={(current bounding box.center)},
  x={($(current bounding box.east)-(current bounding box.center)$)},
  y={($(current bounding box.north)-(current bounding box.center)$)}] 
  \path[nodes={fill=white}] (0,0) node[scale=2]{$e$}
  foreach \X in {0,...,3} {(\X*90:1/2) node[scale={2/sqrt(2)}] {$\mysymb{\X}$}
   foreach \Y [evaluate=\Y as \Ymod using {int(Mod(\Y,4))}] in {\the\numexpr\X-1\relax,\X,\the\numexpr\X+1\relax}
   {($(\X*90:1/2)+(\Ymod*90:1/4)$)node[scale={2/sqrt(3)}] 
   {$\ifnum\X=\Ymod 
   \mysymb{\the\numexpr\X+4}
   \else
   \mysymb{\X}\mysymb{\Ymod}
   \fi$}}};
  \draw[thick] (45:{sqrt(2)/5}) -- (45:{sqrt(1/2)*1.2}) -- (0,1.2)
   -- (-1.2,0) -- (0,-1.2)  -- (-45:{sqrt(1/2)*1.2}) -- (-45:{sqrt(2)/5}) --
   cycle; 
  \draw[thick] (135:{sqrt(2)/5}) -- (135:{sqrt(1/2)*1.1})
   -- (-1.1,0) --  (-135:{sqrt(1/2)*1.1}) --
   (-135:{sqrt(2)/5}) -- cycle;  
 \end{scope} 
\end{tikzpicture}
\end{document}

enter image description here

4
  • "Eccellente" also for you! :-) +1.
    – Sebastiano
    Oct 12, 2019 at 19:29
  • Thank you a lot! Oct 12, 2019 at 22:27
  • Wow, this is cool! I never heard about the lindenmayersystems library, thanks for showing it! :D
    – Vinzza
    Oct 14, 2019 at 9:23
  • @Vinzza Thanks! But you should really thank Mark Wibrow, the author of this answer, which seems to be the origin of the OP's code, which I just copied.
    – user194703
    Oct 14, 2019 at 9:34
7

One easy way to draw this is to do it recursively with TikZ!

For example like that:

\documentclass[tikz,border=5mm]{standalone}

\def\recdraw#1#2#3#4{
  %% #1 : Length of the current path
  %% #2 : Current position
  %% #3 : Current angle
  %% #4 : Number of recursion left
  \ifnum#4>0
  \begin{scope}[shift={(#2)}]
    \draw (0,0) -- (#3:#1);
    \recdrawB{.5*#1}{(#3:#1)}{#3}{\the\numexpr#4-1}
    \draw (0,0) -- (90+#3:#1);
    \recdrawB{.5*#1}{(#3+90:#1)}{\the\numexpr#3+90}{\the\numexpr#4-1}
    \draw (0,0) -- (-90+#3:#1);
    \recdrawB{.5*#1}{(#3-90:#1)}{\the\numexpr#3-90}{\the\numexpr#4-1}
  \end{scope}
  \fi
}

\def\recdrawB#1{
  \pgfmathsetmacro\foo{#1}\expandafter\recdraw\expandafter{\foo}
}


\begin{document}

\begin{tikzpicture}[scale=4]

  \foreach \r in {0,90,180,270}{
    \draw (0,0) -- (\r:1);
    \recdraw{.5}{\r:1}{\r}{7}
  }

\end{tikzpicture}

\end{document}

which gives Cayley Graph

Note that it's not perfect, and the use of pic would certainly be prettier, but I haven't mastered pics yet... :(

By the way, the function \recdrawB is used here to do some calculation so we don't keep the ".5*.5*.5*..." (it speed up the process). But it would certainly be much faster (but a little less recursive) to find a way to avoid doing length computation (maybe with pics or with global variable).

The rest of the draw is not very hard, I'll do it later if you need (and if I have the time)!

1
  • 2
    Molto bene! +1.
    – user194703
    Oct 11, 2019 at 23:06

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .