0

I would like to draw the graph in the picture below using LaTeX, I want it to be in nice better shape. 1.) The position of the edge labels I would like to center it in middle over or below the edge as in the picture and does not conflict the other labels.


\documentclass[12pt]{article}
\usepackage{graphicx}
\usepackage{tabularx}
\usepackage{comment}
\usepackage{subcaption}
\usepackage{caption}
\usepackage{lscape}
\usepackage{calc}
\usepackage{tikz}
\usepackage{tikz}
\usetikzlibrary{fit,positioning,shapes.geometric}
\begin{document}

\begin{figure}[H] \begin{center}\setlength\extrarowheight{7pt} \begin{minipage}[b]{0.4\textwidth} \begin{tikzpicture}[x=1.5cm, y=1cm] %\tikzstyle{every node}=[draw,shape=circle]; %\node[shape=circle,draw=black, scale=0.7,line width=1.5pt] (v0) at (0,0) {$\textbf{0}$}; \path (0:0cm) node[draw,shape=circle, scale=0.7,thick] (v0) {$a1$}; \path (20:2cm) node[draw,shape=circle, scale=0.7,thick] (v1) {$a2$}; \path (60:2cm) node[draw,shape=circle, scale=0.7,thick] (v2) {$a3$}; \path (120:2cm) node[draw,shape=circle, scale=0.7,thick] (v5) {$a4$}; \path (160:2cm) node[draw,shape=circle, scale=0.7,thick] (v6) {$a5$}; \path (70:4cm) node[draw,shape=circle, scale=0.7,thick] (v11) {$a6$}; \path (50:4cm) node[draw,shape=circle, scale=0.7,thick] (v12) {$a7$}; \path (110:4cm) node[draw,shape=circle, scale=0.7,thick] (v13) {$a8$}; \path (130:4cm) node[draw,shape=circle, scale=0.7,thick] (v14) {$a9$}; %\path (90:1.9cm) node[draw=none,shape=circle, scale=0.7,thick] (a10) ; \path (-80:2cm) node[draw,shape=circle, scale=0.7,thick] (v16) {$a11$}; \path (-120:2cm) node[draw,shape=circle, scale=0.7,thick] (v17) {$a12$}; \path (-110:4cm) node[draw,shape=circle, scale=0.7,thick] (v18){$a13$}; \path (-130:4cm) node[draw,shape=circle, scale=0.7,thick] (v19) {$a14$}; \path thick edge[black] node[below] {\color{black} $a15$} (v1); %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \path thick edge[black] node[above,right] {\color{black} \small $n1$} (v2); \path thick edge[black] node[left] {\color{black} \small $n2$} (v0); \path thick edge[black] node[left] {\color{black} \small $n3$} (v5); \path thick edge[black] node[left] {\color{black} {\small $n4$}} (v6); \path thick edge[black] node[below] {\color{black} \small $n5$} (v0); \path thick edge[black] node[left] {\color{black} \small $n6$} (v11); \path thick edge[black] node[below] {\color{black} {\small $n7$}} (v12); \path thick edge[black] node[below left] {\color{black} \small $n8$} (v12); %\draw %(v11) -- (v12) node[pos=.5,above=1mm right=1mm] {$n9$} \path thick edge[black] node[right] {\color{black} \small $n10$} (v13); \path thick edge[black] node[below left] {\color{black} \small $n11$} (v14); \path thick edge[black] node[above left] {\color{black} \small $n12$} (v14); \path thick edge[black] node[right] {\color{black} \small $n13$} (v16); \path thick edge[black] node[left] {\color{black} \small $x$} (v17); \path thick edge[black] node[below] {\color{black} \small $y$} (v17); \path thick edge[black] node[right] {\color{black} \small $z$} (v18); \path thick edge[black] node[left] {\color{black} \small $w$} (v19); \path thick edge[black] node[below] {\color{black} \small $f$} (v19); \end{tikzpicture}

      \end{minipage}

\quad %\end{center} % \end{figure} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %\begin{figure}[H] %\begin{center}\setlength\extrarowheight{7pt} \begin{minipage}[b]{0.4\textwidth} \begin{tikzpicture}[x=0.7cm, y=1cm] %First place the vertices. Note the names correspond to the labels. \node[shape=circle,draw=black, scale=0.7,thick] (v0) at (0,0) {$0g$}; \node[shape=circle,draw=black, scale=0.7,thick] (v8) at (42:3) {$t$}; \node[shape=circle,draw=black, scale=0.7,thick] (v9) at (105:2.8) {$y$} ; \node[shape=circle,draw=black, scale=0.7,thick] (v11) at (155:3) {$tt$} ; \node[shape=circle,draw=black, scale=0.7,thick] (v6) at (205:3) {$e$} ; \node[shape=circle,draw=black, scale=0.7,thick] (v2) at (227:4) {$w$} ; \node[shape=circle,draw=black, scale=0.7,thick] (v5) at (262:2) {$q$} ;

\foreach \x/\y/\lab in {0/8/left,0/7/below,0/9/right,0/11/below left,0/5/right,0/6/above left,5/2/below right,6/2/left,9/11/above left,7/8/above right}
\draw[thick] (v\x)--node[above, \lab] {\pgfmathparse{int(abs(\x-\y))}{{\pgfmathresult}}} (v\y);
%\draw[thick] (v\x)--node[above, \lab, text=blue] {\pgfmathparse{int(abs(\x-\y))}{\pgfmathresult}} (v\y);  
\end{tikzpicture}

      \end{minipage}

    \end{center}
    \end{figure}

\end{document}

Alex
  • 79
  • 5

1 Answers1

3

OK, I'll try again, but you'll have to finish it...

\documentclass[12pt]{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
    \tikzset{vnode/.style={draw,thick,circle,minimum width=1cm,inner sep=0pt}};
    \def\dist{3}

    % Nodes

    \begin{scope}[every node/.style={vnode}]
        \node (a1) {$a_1$};
        \foreach \i [count=\ang from 2] in {2,3,11,10,9,6}
            {
            \path (a1) --++ (60*\ang:\dist) node (a\i) {$a_{\i}$};
            }

        \foreach \i [count=\ang] in {5,4}
            {
            \path (a2) --++ (30+60*\ang:\dist) node (a\i) {$a_{\i}$};
            }

        \foreach \i [count=\ang from 0] in {8,7}
            {
            \path (a6) --++ (30+60*\ang:\dist) node (a\i) {$a_{\i}$};
            }

        \foreach \i [count=\ang from 0] in {12,13}
            {
            \path (a11) --++ (210+60*\ang:\dist) node (a\i) {$a_{\i}$};
            }
    \end{scope}

    % Paths

    \path%[every node/.style={sloped}]
        (a1)    edge node[left] {N6} (a2)
                edge node[above] {N5} (a3)
                edge node[left] {N7} (a11)
                edge node[right] {N12} (a10)
                edge node[above] {N13} (a9)
                edge node[right] {N14} (a6)
        (a2)    edge node[right] {N3} (a5)
                edge node[below left] {N2} (a4)
        (a4)    edge node[above left] {N1} (a5)

        % To be continued...
    ;

\end{tikzpicture}

\end{document}

not finished

Remember it's only one straightforward approach to let you learn from it. Be kind and do your part, now ;)

SebGlav
  • 19,186