0

How can I draw the following graph with tikz? Two cycles connected

Edgar
  • 17
  • Welcome to TeX.SE. This link can be a starting point: https://tex.stackexchange.com/questions/166083/showing-weights-on-tikz-graph-using-draw-edge-commands – Sebastiano Mar 28 '18 at 20:11
  • Welcome to TeX.SX. Questions about how to draw specific graphics that just post an image of the desired result are really not reasonable questions to ask on the site. Please post a minimal compilable document showing that you've tried to produce the image and then people will be happy to help you with any specific problems you may have. See minimal working example (MWE) for what needs to go into such a document. – Stefan Pinnow Mar 28 '18 at 20:11
  • -1 from me; details in Steffan's comment – cmhughes Mar 29 '18 at 08:16

3 Answers3

8

Well, a draw-it-for-me is good for code golfing

\documentclass[tikz]{standalone}
\usetikzlibrary{shapes.geometric}
\def\myarray{{1,2,5,6,3,4}}
\begin{document}
\begin{tikzpicture}[sty/.style={regular polygon,regular polygon sides=6,minimum size=4cm,#1}]
\foreach\x/\xo/\xs in{1/xscale=-1/0,2/rotate=60/6}{
\path node[sty/.expanded=\xo]at(\xs,0)(h\x){} node[circle,draw]at (h\x.corner 1)(h\x-1){1};}
\foreach \x[evaluate={\xa=\myarray[\x-1]}, remember=\x as \xp (initially 1)] in {2,...,6,1}{
  \foreach \y/\ys in {1/right,2/left}{
    \draw node[circle, draw] (h\y-\x) at (h\y.corner \x) {\xa} (h\y-\xp) -- (h\y-\x) 
                            node[midway,auto=\ys,swap] {\ifnum\xa=5 $\lambda$\else1\fi};}}
\draw (h1-3) -- (h2-2) node[midway,above]{1};
\end{tikzpicture}
\end{document}

enter image description here

percusse
  • 157,807
  • 1
    I know directly drawing is shorter but where is the fun that? – percusse Mar 28 '18 at 21:06
  • It is too easy to hard code {1,2,5,6,3,4} ;) And what about a formula ? What about mod(div(\i-1,2)*2,3)*2+mod(\i-1,2)+1 ? – Kpym Mar 28 '18 at 22:25
  • Dumb question: did you render your screenshot with newpxtext,newpxmath or something? It renders in CMR for me, and I don't see any reason why it shouldn't. – wchargin Mar 29 '18 at 01:37
  • @wchargin Ouch, indeed it's mathptmx the default font package KtikZ adds automatically. Good catch ! – percusse Mar 29 '18 at 08:18
5

A somehow easier (in level) than @percusse's

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc}
\newcounter{tempc}
\begin{document}

\def\rpol{2 cm}
\def\rcirc{1cm}
\begin{tikzpicture}
\foreach \angle/\num[count=\i from 1] in {0/5,60/2,120/1,180/4,240/3,300/6,360/0}
{
\ifnum\i<7
\path ($(0,0)+(\angle:\rpol)$) node[draw,circle,minimum width=\rcirc ] (A\i) {\num};
\fi
\setcounter{tempc}{\i}
\addtocounter{tempc}{-1}
\ifnum\i=1
\relax
\else 
\ifnum\i=7
\draw(A6)--(A1)node[midway,shift=({\angle-15}:0.3cm)]{ 1};
\else
\draw (A\i)--(A\thetempc)node[midway,shift=({\angle-15}:0.3cm)]{\ifnum\i=2 $\lambda$\else 1\fi};
\fi
\fi
}
\foreach \angle/\num[count=\i from 1] in {180/2,240/5,300/6,360/3,60/4,120/1,180/0}
{
\ifnum\i<7
\path ($({3*\rpol},0)+(\angle:\rpol)$) node[draw,circle,minimum width=\rcirc ] (B\i) {\num};
\fi
\setcounter{tempc}{\i}
\addtocounter{tempc}{-1}
\ifnum\i=1
\relax
\else 
\ifnum\i=7
\draw(B6)--(B1)node[midway,shift=({\angle-15}:0.3cm)]{ 1};
\else
\draw (B\i)--(B\thetempc)node[midway,shift=({\angle-15}:0.3cm)]{\ifnum\i=2 $\lambda$\else 1\fi};
\fi
\fi
}
\draw(A1)--(B1) node[midway,yshift=0.3cm] {1};
\end{tikzpicture}
\end{document}

enter image description here

koleygr
  • 20,105
4

Golfing ? With single one argument loop :

\documentclass[tikz,border=7pt]{standalone}
\usetikzlibrary{shapes.geometric,math}
\tikzset{
  hexleft/.style = {xscale=-1},
  hexright/.style = {rotate=60},
  hex/.pic={
    \node[hex#1,draw,fill=white,regular polygon,regular polygon sides=6,minimum size=4cm](-h){};
    \tikzmath{
      let \k = $\lambda$;
      int \i,\l,\n,\m; \n=2;
      for \i in{0 ,...,5}{
        \l=mod(\i+1,6)+1; \m = mod(\n,6) + 1;
        {\path (-h.corner \n) node[draw,circle,fill=white] {\l} -- (-h.corner \m) node[midway,auto=#1]{\k};};
        \n = mod(\n+mod(\i+1,2)*2,6)+1;\k=1;
      };
    };
  }
}
\begin{document}
  \begin{tikzpicture}
     \draw (0,0) pic(A){hex={left}} -- node[above]{1} ++(7,0) pic(B){hex={right}};
  \end{tikzpicture}
\end{document}

enter image description here

Kpym
  • 23,002