3

I want to make this graph. I found a few different things in the PGF manual that were kind of similar but I couldn't find a way to draw:

  1. The central hub/node (vertex)
  2. The straight twin edges (i.e. the double lines/arrows)

enter image description here

Here's me experimenting with a few things according to the manual, but they're not even close:


\documentclass[10pt]{article}
\usepackage{tikz}
\usepackage{pgfplots}
\pgfplotsset{compat=1.16}
\usetikzlibrary{arrows.meta}
\usetikzlibrary{graphs}
\usetikzlibrary{graphs.standard}

\begin{document}%%

\tikz \graph [clockwise=6]       { a, b, c, d, e, f  [<->]}; 
\tikz \graph [clockwise=6,clique]{ a, b, c, d, e, f  [<->]}; 
\tikz \graph [clockwise]         { subgraph I_n [n=6,<->] }; 
\tikz \graph [clockwise,clique]  { subgraph I_n [n=6,<->] }; 
\tikz \graph [clockwise]         { subgraph K_n [n=6,<->] }; \\
\tikz \graph [clockwise,clique]  { subgraph K_n [n=6,<->] }; 
\tikz \graph [clockwise]         { subgraph C_n [n=6,<->] }; 
\tikz \graph [clockwise,clique]  { subgraph C_n [n=6,<->] }; 
\tikz \graph [clockwise]         { subgraph P_n [n=6,<->] }; 
\tikz \graph [clockwise=6,multi] {{ a, b, c, d, e, f };
a <->[bend left] b;
a <->[bend right] b; 
b <->[bend left] c;
b <->[bend right] c; 
c <->[bend left] d;
c <->[bend right] d; 
d <->[bend left] e;
d <->[bend right] e; 
e <->[bend left] f;
e <->[bend right] f; 
f <->[bend left] a;
f <->[bend right] a; 
};    

%\tikz \graph [spring electrical layout, horizontal=0 to 1] { 0 [electric charge=1] -- subgraph C_n [n=6] }; 
% ^^^ couldn't get this one to work at all for some reason

\end{document}%%

enter image description here

Stefan Pinnow
  • 29,535
voices
  • 2,039

3 Answers3

5

The graph layout is easy, it is already covered in the second example on p. 269 of the pgfmanual (of course with C_n replaced by I_n). The two parallel arrows can easily be cast in a style if the paths are straight.

\documentclass[tikz,border=3.14mm]{standalone}
\usetikzlibrary{graphs,graphs.standard}
\usetikzlibrary{decorations.pathreplacing,calc}
\tikzset{two parallel arrows/.style={decorate,decoration={show path construction,
      lineto code={
       \draw [stealth-stealth] ($(\tikzinputsegmentfirst)!#1!90:(\tikzinputsegmentlast)$) 
        -- ($(\tikzinputsegmentlast)!#1!-90:(\tikzinputsegmentfirst)$); 
       \draw [stealth-stealth] ($(\tikzinputsegmentfirst)!#1!-90:(\tikzinputsegmentlast)$) 
        -- ($(\tikzinputsegmentlast)!#1!90:(\tikzinputsegmentfirst)$); 
      }}},two parallel arrows/.default=3pt}
\begin{document}
\begin{tikzpicture}
\graph  [nodes={draw, circle,inner sep=1em,font=\sffamily},radius=2cm] 
{ subgraph I_n [n=6, clockwise,name=outer,V={A,B,C,D,E,F}]  
--[shorten <=1pt, shorten >=1pt,
two parallel arrows]  {a} };
\end{tikzpicture}

\begin{tikzpicture}
\graph [nodes={draw, circle,inner sep=1em,font=\sffamily}, 
clockwise, radius=1.5cm] {
subgraph I_n [name=inner, n=1,radius=0cm,/tikz/text opacity=0] 
--[shorten <=1pt, shorten >=1pt,two parallel arrows]
subgraph I_n [name=outer, n=6,V={A,B,C,D,E,F}] };
\end{tikzpicture}
\end{document}

enter image description here

If you consider also curved paths, you may use this answer because it will allow you to use them for curved arrows, too.

\documentclass[tikz,border=3.14mm]{standalone}
\usetikzlibrary{graphs,graphs.standard,arrows.meta}
\makeatletter
\pgfkeys{ % from https://tex.stackexchange.com/a/232468/121799
  /pgf/arrow keys/.cd,
  Bidirectional/.style={
    length = +1.05pt 1.925 1,
    shear
  },
  shear/.code={
    \pgfarrowsthreeparameters{#1}%
    \expandafter\pgfarrowsaddtooptions\expandafter{\expandafter\pgfarrowslinewidthdependentnew\pgfarrowstheparameters\pgfarrowshear\pgf@x}%
  },
  shear/.default = +0pt -.5 -.5
}
\newdimen\pgfarrowshear
\pgfarrowshear0pt
\def\pgfarrowslinewidthdependentnew#1#2#3{%
  \pgf@x#1%
  \ifdim\pgfinnerlinewidth>0pt%
    \pgf@arrows@inner@line@width@depnew{#2}{#3}%
  \else%  
    \advance\pgf@x by#2\pgflinewidth%
  \fi%
}
\def\pgf@arrows@inner@line@width@depnew#1#2{%
  % #1 * outer line width + #2 * inner line width = our new one = the following
  % (#1/2) * full line width + (#2-#1/2) * inner line width)
  % Compute "real" line width
  \pgf@xa.5\pgflinewidth%
  \pgf@xa#1\pgf@xa%
  \advance\pgf@x by\pgf@xa%
  \pgf@xa\pgfinnerlinewidth%
  \pgf@xb.5\pgf@xa%
  \advance\pgf@x by#2\pgf@xa%
  \advance\pgf@x by-#1\pgf@xb%
}
\def\pgf@arrow@drawer@shift#1#2#3{
  \pgftransformyshift\pgfarrowshear%
  \pgf@xb#2\pgftransformxshift{-\pgf@xb}%
  \pgf@xc#1%
  \advance\pgf@xc by\pgfarrowsep%
  \advance\pgf@xc by-\pgf@xb%
}
\makeatother
\begin{document}
\begin{tikzpicture}[bidi/.style={thick,double,double
distance=3pt,{<[Bidirectional]}-{>[Bidirectional]}}]
\graph  [nodes={draw, circle,inner sep=1em},empty nodes,radius=2cm] 
{ subgraph I_n [n=6, clockwise,name=outer] --[bidi,shorten <=1pt, shorten >=1pt] {a} };
\end{tikzpicture}
\end{document}

enter image description here

  • That's the opposite of what I want you to take away from this. A: Your first diagram is a more accurate reproduction of mine that the chosen answer. B: As a rule of thumb, it occurs to me that your skills are second to none. But therein lies the problem, C: Your code is far too advance for most (if not all) of us and it's daunting. I don't even know where to begin to understand it because, D: You don't really explain it. Don't get me wrong, it's quick and convenient and your efforts don't go unappreciated, but E: I don't want to rely on you. I want to understand so I can do it myself. – voices Jun 22 '19 at 10:23
  • @tjt263 I can't follow your arguments. It looked to me as a question on graph drawing, and I explain that this graph is already in the pgfmanual, and mention the page where it can be found. If you do not understand something, you can ask. I was actually glad to see that question because it was on something that is not like all these repeating posts. But now of course we are back at the "how can I draw this?" -> "here is a way" type of posts. Is specifically highlighted Symbol 1's post because it is something novel. No, it is not simple, but certainly not just copied from somewhere. –  Jun 24 '19 at 01:31
  • I'm saying: You have skills, congratulations, that's good for you; you can program some fantastic diagrams. We're not all on the same level. If I could read your code and understand it, I probably would have chosen it. But I can't, so I didn't. The goal is always going to be to draw or typeset something. The problem is this answer's just code and images. No commentary or attempt to explain what's happening or how or why, etc. You only give us enough information to copy you verbatim, not enough to adapt it and be creative. Show us all how to do it for ourselves and you eliminate repetition. – voices Jul 05 '19 at 16:11
  • @tjt263 How would I know which information is lacking if you don't ask? I do learn from examples and from references to positions in the manual. Let's stop this and depart peacefully. You won't change your opinion and I won't change mine. But yes, in the future I will refrain a bit more from putting effort in answers if all I get back are such comments. –  Jul 05 '19 at 16:23
  • What are you talking about? It's not about opinions. It's a fact. You spat it when I picked someone else answer. I'm trying to explain to you as respectfully as possible why I didn't pick yours instead. If you can't help but feel insulted or offended in some way by that, harden up, take the advice, it's constructive criticism. If you feel unappreciated, don't. I'm on your side. I really do genuinely appreciate your contributions and I'm sure others do too. I think you'll agree, it's more worthwhile to teach someone to do something (for themselves) than to do it for them (on an ongoing basis). – voices Jul 05 '19 at 17:00
  • @tjt263 I beg to disagree. You are saying I do not explain anything but don't say what. BTW, I was never contacting you. You started the discussion. And why can't I say that I disagree with you without offending you? I do not know you, how on earth would I know at which level you want an explanation. If you want to feel offended, that's your choice, but this was never my intention. I stop here. –  Jul 05 '19 at 18:22
  • I wasn't offended. I thought you were. – voices Aug 05 '19 at 08:31
  • @tjt263 It is all irrelevant now. This account is scheduled to be deleted yesterday. Should be gone any minute now. –  Aug 05 '19 at 15:46
4

With plain tikz using calc library for arrows positioning:

enter image description here

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

\begin{document}
    \begin{tikzpicture}[
every node/.style = {circle, draw, minimum size=2em},
       arr/.style = {Stealth-Stealth, semithick, shorten <=#1, shorten >=#1},
                        ]
\node (c)  {};
    \foreach \i [count=\j from 0] in {A,...,F}
\node (n\j) at (150-\j*60:24mm) {\i};
%
    \foreach \i in {0,1,...,5}
{
\draw[arr=1em] ($(c)!1mm!90:(n\i)$) -- ($(n\i)!1mm!-90:(c)$);
\draw[arr=1em] ($(c)!1mm!-90:(n\i)$) -- ($(n\i)!1mm!90:(c)$);
}
   \end{tikzpicture}
\end{document}
  • for positioning of nodes are used polar coordinates (in the loop)
  • for determining of the coordinates for arrows are used the syntax of partway modifiers provided by the calc package. This coordinate calculation is described in TikZ \& PGF manual, pp 146 -- 147:
($(start coordinate)!distance!angle:(end coordinate)$)

where the coordinate is displaced from (start coordinate) for distance perpendicular (i.e. angle of displacement is 90 degrees) on line (start coordinate) -- (end coordinate)

Zarko
  • 296,517
  • Nice one. I like it for it's relative simplicity. Still, would you mind including some comments or a brief explanation of what does what exactly? – voices Jun 20 '19 at 20:34
  • @tjt263, i hope that added explanation is sufficient for understanding of my code. – Zarko Jun 20 '19 at 21:12
  • It could be a lot better. I mean, it's good, but there are other things that could do with mentioning. Like, why you do it twice (is it because the arrows are in pairs?), or that \node (c) {} denotes the centre node. I assume \node (n\j) at (150-\j*60:24mm) {\i}; refers to each of the nodes in the outer ring. Is arr/.style like a class object that determines the arrow style for the whole document? Why do you need \i and \j? why not just iterate over \n directly? I see you import the calc library, but don't see it being called as a function. I do appreciate it though, thanks. – voices Jun 22 '19 at 10:01
0
\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{automata,arrows,calc,positioning}

\begin{document}

\begin{tikzpicture}[>=stealth',shorten >=1pt,auto,node distance=1.5cm and 4cm,scale=1, transform shape,align=center,minimum size=3em]

    \node[state]    (E)                              {E};  
    \node[state]    (B)    [right=of E]              {B};
    \node[state]    (A)    [above=of $(E)!0.5!(B)$]  {A};
    \node[state,xshift=-0.6cm]    (C)    [below=of B]              {C};
    \node[state,xshift=0.6cm]    (D)    [below=of E]              {D};
    \node[state]    (F)    [below=of A]              {};

    \draw[double distance=5pt] 
    (F) -- (A) 
    (F) -- (B)
        (F) -- (C)
        (F) -- (D)
        (F) -- (E);

\end{tikzpicture}


\end{document}
harryparp
  • 565