4

I am trying to produce a diagram in the shape of a dodecagon, but using the approach I am more comfortable with I would need to be able to change the separation of individual pairs of columns and rows. Is that possible in TikZ-cd?

I would prefer to solve this problem using only TikZ-cd, but if that is not possible I would accept an answer offering an alternative method.

Here is my initial attempt at a dodecagon:

\documentclass{report}

\usepackage{tikz-cd}
\usepackage{caption}

\begin{document}

\begin{figure}
\centering
\begin{tikzcd}[column sep=1cm, row sep=1cm]
    &   &   c_{0}\arrow{r}\arrow{drr}   &   c_{1}\arrow{dr}\arrow{ddrr} &   &   \\
    &   c_{11}\arrow{ur}\arrow{urr} &   &   &    c_{2}\arrow{dr}\arrow{ddr}  &  \\
    c_{10}\arrow{ru}\arrow{rruu}     &  &   &   &   &    c_{3}\arrow{d}\arrow{ddl}   \\
    c_{9}\arrow{u}\arrow{uur}   &   &   &   &   &    c_{4}\arrow{dl}\arrow{ddll}     \\
    &    c_{8}\arrow{ul}\arrow{uul}     &   &   &    c_{5}\arrow{dl}\arrow{dll}  &    \\
    &   &   c_{7}\arrow{ul}\arrow{uull} &   c_{6}\arrow{l}\arrow{ull}   &   &
\end{tikzcd}
\caption*{Dodecagon}
\end{figure}

\end{document}

enter image description here

If it helps, the separation between the 1º and 2º columns and between the 5º and 6º must be reduced to 0,5cm, while the separation between the 2º and 3º columns and the 4º and 5º must be reduced to 0,8660254cm. The same must be done for the rows.

(EDIT: I found out how to change the separations of individual pairs of columns and rows, but the resulting diagram still does not look like a regular dodecagon...

\documentclass{report}

\usepackage{tikz-cd}
\usepackage{caption}

\begin{document}

\begin{figure}
\centering
\begin{tikzcd}
    &[0.5cm]    &[0.8660254cm]  c_{0}\arrow{r}\arrow{drr}   &[1cm]  c_{1}\arrow{dr}\arrow{ddrr} &[0.8660254cm]  &[0.5cm]    \\[0.5cm]
    &   c_{11}\arrow{ur}\arrow{urr} &   &   &    c_{2}\arrow{dr}\arrow{ddr}  &  \\[0.8660254cm]
    c_{10}\arrow{ru}\arrow{rruu}     &  &   &   &   &    c_{3}\arrow{d}\arrow{ddl}   \\[1cm]
    c_{9}\arrow{u}\arrow{uur}   &   &   &   &   &    c_{4}\arrow{dl}\arrow{ddll}     \\[0.8660254cm]
    &    c_{8}\arrow{ul}\arrow{uul}     &   &   &    c_{5}\arrow{dl}\arrow{dll}  &    \\[0.5cm]
    &   &   c_{7}\arrow{ul}\arrow{uull} &   c_{6}\arrow{l}\arrow{ull}   &   &
\end{tikzcd}
\caption*{Dodecagon}
\end{figure}

\end{document}

enter image description here

I assume either I made a mistake in my calculations or I misunderstood some technical aspect of the package TikZ-cd...)

  • You may be better off with the shapes.geometric library and use \nod[regular polygon,regular polygon sides=12,minumu size=6cm]{};, say. – Schrödinger's cat Feb 19 at 21:17
6

New answer

Here is a dodecagon diagram built in pure Tikz with the chains library which is compilable with all engines (LaTeX, pdfLaTeX, XeLaTeX, LuaLaTeX).

Updated code (on request of OP)

Here, I placed indexed labels for the arrows inside the dodecagon and the same label for the others.

For the internal arrows, I chose these options:

font=\tiny,fill=white,outer sep=0pt,inner sep=1pt

and for you to understand the difference for the others with these options:

font=\scriptsize,auto=right,outer sep=0pt,inner sep=1pt 

If any of them require explanation, say so.

screenshot

\documentclass[tikz, margin=3mm]{standalone}
\usetikzlibrary {chains}
\usetikzlibrary{arrows.meta}
\begin{document}

\begin{tikzpicture}[start chain= dodecagon placed {at=(120+\tikzchaincount*-30:2.5)}]
\foreach \i in {0,...,11}
    {\node [on chain] {$c_{\i}$};
    }
\foreach \i [evaluate={
            \next=int(1+mod({\i},12));
            \nextnext=int(1+mod({\i+1},12));}] 
        in {1,...,12}{
\draw[->] (dodecagon-\i)--node[font=\tiny,fill=white,outer sep=0pt,inner sep=1pt]{x}(dodecagon-\next);
\draw[->] (dodecagon-\i)to[bend right=20]node[font=\scriptsize,auto=right,outer sep=0pt,inner sep=1pt]{$l_{\i}$}(dodecagon-\nextnext);
}

\end{tikzpicture}
\end{document}

Old code

screenshot

\documentclass[tikz, margin=3mm]{standalone}
\usetikzlibrary {chains}
\usetikzlibrary{arrows.meta}
\begin{document}

\begin{tikzpicture}[start chain= dodecagon placed {at=(120+\tikzchaincount*-30:2.5)},>={Stealth[round,sep]}]
\foreach \i in {0,...,11}
    {\node [on chain] {$c_{\i}$};
    }
\foreach \i [evaluate={
            \next=int(1+mod({\i},12));
            \nextnext=int(1+mod({\i+1},12));}] 
        in {1,...,12}{
\draw[->] (dodecagon-\i)--(dodecagon-\next);
\draw[->] (dodecagon-\i)to[bend right=15](dodecagon-\nextnext);
}

\end{tikzpicture}
\end{document}

Old answer :

Here is a graph created with Tikz (but not with tikz-cd) using the circular library which must be compiled with Lualatex.

screenshot

\documentclass[border=5mm]{standalone}
\usepackage{tikz}
\usetikzlibrary {graphs,graphdrawing} 
\usegdlibrary {circular}
\usetikzlibrary{arrows.meta,bending}
\begin{document}
\begin{tikzpicture}[>={Stealth[round,sep]}]
\graph [simple necklace layout,
 node distance=1.5cm,
grow'=south,
math nodes,
edges={>={Stealth[round,sep,bend]}}]
{ c_0 -> c_1 -> c_2  -> c_3 -> c_4 -> c_5 -> c_6 -> c_7 -> c_8 -> c_9 -> c_{10} -> c_{11} -> c_0};

\graph [use existing nodes,
math nodes,
edges={bend right=15,>={Stealth[round,sep,bend]}}]{
c_1 -> c_3 -> c_5  -> c_7 -> c_9 -> c_{11} -> c_1,c_2 -> c_4 -> c_6 -> c_8 -> c_{10}->c_0
 };
\end{tikzpicture}
\end{document}
|improve this answer|||||
  • It is a beautiful diagram indeed, but I need to ask: would you happen to know if my original approach really has no way of working out? – GVT Feb 19 at 23:24
  • @GVT Yes, it can work, but it involves complicated manual calculations to ensure that the nodes are perfectly aligned with the vertices of a regular dodecagon. In my opinion, computer science should simplify and automate calculations, not complicate them. Thus, it is in my opinion preferable to use the tools best adapted to solve each problem. – AndréC Feb 20 at 7:17
  • I get your point, but since I will have to fiddle with the diagram later, I prefer to stick to a method I can understand: hence I try to stay in TikZ-cd... Regardless of how beautiful the end result of your code is, I can't quite follow what's going on (because of my own ignorance, but still...). – GVT Feb 20 at 19:42
  • @GVT If you have questions about the code, ask them, I'll update my answer according to your requests for clarification (Since this is pure TikZ, I don't know what can cause you problems in this code...). – AndréC Feb 20 at 19:56
  • It is difficult for me to understand the code just because my understanding of LaTeX is so shallow! I am sure there is nothing wrong with it. So, two questions: how can I change the arrows to match the style present in my example? And how can I label the arrows? – GVT Feb 21 at 18:23
4

Just plain TikZ, all connections, no hard-coded values but just loops, everything in a single path. Works with all standard compilers (pdflatex, xelatex, lualatatex) and can thus be used in a paper that is to be submitted to the arXiv, say.

\documentclass[tikz,border=3mm]{standalone}
\usetikzlibrary{arrows.meta,bending}
\begin{document}
\begin{tikzpicture}
 \path[every edge/.append style={-{Stealth[bend]}}] foreach \X in {0,...,11}
 { (105-\X*30:4) node (c\X) {$c_{\X}$}}
  foreach \X [remember=\X as \LastX (initially 11),
    evaluate=\X as \LLastX using {int(Mod(\X+10,12))}] in {0,...,11}
  { (c\LastX) edge (c\X)
  \ifodd\X
   (c\LLastX) edge[bend left=60] (c\X)
  \else
   (c\LLastX) edge[bend right=5] (c\X) 
  \fi};
\end{tikzpicture}
\end{document}

enter image description here

|improve this answer|||||

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.