0

I have the following code


\documentclass[tikz,border=3mm]{standalone}
\usetikzlibrary{graphs}
\usetikzlibrary{graphs.standard}
\begin{document}
\begin{tikzpicture}
\begin{scope}[nodes={circle, draw,minimum size=1.8em}]
 \graph[empty nodes] { 
  {subgraph I_n [n=12,radius=2.1cm, counterclockwise,phase=105] -- 
    x[label={[draw,minimum size=1em]center:{0}}]}; 
  1-- 2, 5-- 6, 7--8, 11 -- 12};
 \path (-{5*cos(40)},0) node (L){} ({5*cos(40)},0) node (R){}; % C4
\end{scope}
\draw (3) node{$a$}-- node[auto,swap]{$e$}(L) node{$b$} -- (4) node{$c$} (9) -- (R) -- (10);

\draw (1) node{$1$}; \draw (2) node{$2$}; \draw (3) node{$3$}; \draw (4) node{$4$}; \draw (5) node{$5$};

\draw (6) node{$6$}; \draw (7) node{$7$}; \draw (8) node{$8$}; \draw (9) node{$9$}; \draw (10) node{$10$};

\draw (11) node{$11$}; \draw (12) node{$12$};

\draw (R) node {$77$};

\draw[-] (1) node[below] {$30$} (2); %\path (node{$1$}) -- node[auto]{<g>} (node{$2$});

\end{tikzpicture} \end{document}


Alex
  • 79
  • 5
  • 1
    Is this a follow up on https://tex.stackexchange.com/questions/544140/graph-with-lateex? – albert May 22 '20 at 16:38
  • 9
    Please don't make more work for other people by vandalizing your posts. By posting on the Stack Exchange (SE) network, you've granted a non-revocable right, under the CC BY-SA 4.0 license for SE to distribute that content. By SE policy, any vandalism will be reverted. If you want to know more about deleting a post, consider taking a look at: How does deleting work? – Glorfindel May 22 '20 at 16:57

1 Answers1

4

In this answer the empty nodes key was used because you showed a screen shot with empty nodes. If you want to fill in numbers, it is much easier to drop this key than manually filling the nodes. Further, if you start an industrial production of edge labels, quotes can be convenient.1

\documentclass[tikz,border=3mm]{standalone}
\usetikzlibrary{graphs,graphs.standard,quotes}
\begin{document}
\begin{tikzpicture}
\begin{scope}[nodes={circle, draw,minimum size=1.8em}]
 \graph { 
  {subgraph I_n [n=12,radius=2.1cm, counterclockwise,phase=105] -- 
    0}; 
  1-- 2, 5-- 6, 7--8, 11 -- 12};
 \path (-{5*cos(40)},0) node (L){} ({5*cos(40)},0) node (R){77}; % C4
\end{scope}
\draw[swap] (3) to["$e$" ](L)  to["$f$"](4) 
(9) to["$g$"] (R) to["$h$"] (10)
(1)  to["$30$" {pos=0.3}] (2);
\end{tikzpicture}
\end{document}

enter image description here

ADDENDUM: Maybe a more verbatim solution makes it easier for you to get what you want.

\documentclass[tikz,border=3mm]{standalone}
\usetikzlibrary{quotes}
\begin{document}
\begin{tikzpicture}[auto,c/.style={circle, draw,minimum size=1.8em},
    every edge quotes={font=\small,draw=none,}]
 \path node[c](0) {$0$}
  foreach \X [count=\Y] in {20,19,10,12,15,18,13,17,8,7,16,14}
 {(75+\Y*30:3) node[c](\X) {$\X$} edge["$\X$" {pos=0.3}] (0)}
 (20) edge["1"](19) (14) edge["2"](16)
 (15) edge["3"](18) (13) edge["4"](17)
 ({-6*cos(15)},0) node[c] (1){$1$} ({6*cos(15)},0) node[c] (2){$2$}
 (1) edge["9"](10) (1) edge["11"](12)
 (2) edge["5"](7) (2) edge["6"](8);
\end{tikzpicture}
\end{document}

enter image description here

1Note, however, that if you use the babel package, you may need to load the TikZ library of the same name, too.

  • 2
    @Alex You can add an edge label e.g. with \path (0) to["$x$"] (10);. –  May 22 '20 at 02:57
  • 2
    @Alex I added a possible answer to your follow-up question. When I answered your first question, the idea was that, since it is related to machine learning, graphs may be a great idea. They are very powerful, but maybe a more direct approach allows you to get familiar with TikZ more quickly. So I added such a version. –  May 22 '20 at 09:40
  • 4
    @Alex I do not understand this request, also because you do not specify a reason. However, I am not going to remove the post. The answer is for everyone, not just for your. It may be useful for others. I am also not susceptible to "unaccepting answer" games. If this is the way you think is appropriate to treat others who try to help, this is your choice. –  May 22 '20 at 16:44
  • 2
    @Alex As I said, I am not susceptible to "unaccepting answer" games. I have seen where they lead to, and I am out of here. –  May 22 '20 at 16:48
  • 5
    @Alex You can always ask a new question if you want to change a few things. You should not change an answered question in a way that the answer loses its validity. Most users, including me, won't comply with that. The idea is that question and answer are helpful for others. You just destroy the original post, which some may have found to be useful. –  May 22 '20 at 16:57
  • 2
    @Schrödinger'scat, despite all the good faith of most users, I see new and strange behavior everyday here ... this is incredible – BambOo May 22 '20 at 17:15
  • 1
    @BambOo This is by far not the first time this happens. Some users change and become constructive users, some users quit, some users start vandalizing. So we will see what happens here. But I was never a fan of the "accept an answer" thingy anyway. –  May 22 '20 at 17:24
  • 1
    @Schrödinger'scat Surprisingly, for me this is a first. Some people have trouble accepting their question may benefit to others it seems – BambOo May 22 '20 at 17:30
  • 1
    @BambOo There is a discussion on this topic. –  May 22 '20 at 17:34
  • @Schrödinger'scat, surely an interesting question ! – BambOo May 22 '20 at 17:41