0

I'm using tikz to draw my graph (a complete graph). I labeled the edges and the vertices and want to add the weight of each vertices on top of it. Here's what I've done:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{graphs,graphs.standard}

\begin{document}
\begin{tikzpicture}
  \graph { subgraph K_n [n=3,clockwise,radius=2cm, nodes={circle,draw}] };
\draw (1) -- node[midway, above right] {4} (2);
\draw (1) -- node[midway, above left] {5} (3);
\draw (2) -- node[midway, below] {6} (3);
\end{tikzpicture}
\end{document}

The weights of each vertices that I want to add are: 10 on vertex 1, 12 on vertex 2, and 14 on vertex 3. Is there a way to do it? Thanks in advance.

1
  • Does answer below solve your problem?
    – Zarko
    Mar 20 at 12:24

1 Answer 1

1

By of pure tikz is simple:

\documentclass[border=3.141592]{standalone}
\usepackage{tikz}
\usetikzlibrary{positioning,
                quotes}

\begin{document}
    \begin{tikzpicture}[
node distance =24mm and 12mm,
C/.style = {circle, draw, minimum size=1em}
                    ] 
\node (v1) [C, label=10] {1};
\node (v2) [C, label=12, above right=of v1] {2};
\node (v3) [C, label=14, below right=of v2] {3};
%
\draw (v1)  to["4"] (v2)    
            to["6"] (v3)    
            to["5"] (v1);
    \end{tikzpicture}
\end{document}

enter image description here Addendum:

With use of LuaLaTeX and TikZ libraries graphs, graphdrawing and gdlibrary circular`:

\documentclass[border=3.141592]{standalone}
\usepackage{tikz}
\usetikzlibrary{graphs,graphdrawing,
                quotes} 
\usegdlibrary {circular}

\begin{document}
    \begin{tikzpicture}[
every label/.append style = {font=\small, text=blue}
                        ]
\graph [simple necklace layout, 
        grow'=down, node sep=22mm,
        nodes={draw,circle},  
        edges={auto, nodes={font=\scriptsize, inner sep=1pt}}
        ] {
    1[label=10] --["4"] 2[label=12] --["6"] 3[label=14] --["5"] 1;
};
\end{tikzpicture}
\end{document}

enter image description here

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.