0

In the following picture there are multiple edges between two vertices. But I am able to draw single edge. So I want to label the number of edges. How can I do it? For example there are $3$ edges between $1$ and $4$. How can I label $3$?

\[\begin{tikzpicture}[scale=3, every loop/.style={}]

    \vertex[fill] (1) at (.5, 1)  [label=above: 1] {}; 
 \vertex [fill](2) at (0,.5) [label=left: 2] {};
\vertex[fill] (3) at (.5,0) [label=above: 3]{};
  \vertex[fill] (4) at (1,0) [label=above: 4] {};   
    \vertex[fill] (5) at (1.5, 0.5) [label=right: 5]  {};  
    \vertex [fill](6) at (1,1) [label=left: 6] {};  
 \draw (1,1)  to[in=-50,out=-130,loop] (1,1);
    \path


        (1) edge (4)
        (1) edge (4)
        (1) edge (4)
        (1) edge (2)
        (2) edge (4)
        (2) edge (5)
        (3) edge (5)
        (3) edge (6)

     ;  
\end{tikzpicture}\]
  • (1) edge node [above] {label} (4), or with use quotes library and (1) edge ["label"] (4). if you will extend your code sniped to complete compilable document, we can simply show this on your picture example. welcome to tex.se! – Zarko Apr 28 at 13:23
  • Thank you very much. But when I label all edges the numbers are not understandable for which edge it is defined. I mean it is not understandable that for which edges the labelling is done. @Zarko – a.nayek Apr 28 at 13:26
  • 1
    well, this is not latex problem :-). please consider my ask and extend your code snippet to complete small document beginning with \documentclass and ending with \end{document} which we can test and than make suggestion how to place your edge labels. – Zarko Apr 28 at 13:30
  • (2) edge["e"{swap,pos=.2}] (4) for example will move the node to the other side of the line (swap does that) and to 20% along the line from 2 to 4, instead of halfway (pos=0.2 does that). (By the way, @Zarko how is the positioning of the edge labels not a latex problem?) – Torbjørn T. Apr 29 at 20:51
  • @TorbjørnT., how to write edges' labels are LaTeX problem and I give him a suggestion how to write them ... however, how are vertex placing and edges labels overlaps is image design problem. since I can't test his code and see how it looking, I can't help him further. So I ask him for MWE. and this ask is not LaTeX problem. – Zarko Apr 30 at 6:16
1

probably you looking for the following:

enter image description here

since you not provide complete small document, which gives information what is \vertex, i reconstruct own code, for which i hope that is similar to what you like to have. in this I made to important changes:

  • remove scale and accordingly multiply each coordinate
  • reduce font size for edge labels
  • define positions for labels so, that they not overlap

    \documentclass[12pt,tikz, margin=3mm]{standalone}
    \usetikzlibrary{arrows.meta,
                    quotes}
    
    \begin{document}
        \begin{tikzpicture}[
    vertex/.style = {circle, fill, inner sep=2pt, outer sep=0pt},
    every edge quotes/.style = {auto=left, sloped, font=\scriptsize, inner sep=1pt}
                            ]
    \node[vertex] (1) at (1.5,3)     [label=above: 1] {};
    \node[vertex] (2) at (0,1.5)     [label=left: 2]  {};
    \node[vertex] (3) at (1.5,0)     [label=left: 3]  {};
    \node[vertex] (4) at (3,0)       [label=right: 4] {};
    \node[vertex] (5) at (4.5,1.5)   [label=right: 5] {};
    \node[vertex] (6) at (3,3)       [label=above: 6] {};
    %
    \path   (1) edge [pos=.35, "a"] (4)
            (1) edge ["b"]  (2)
            (2) edge ["c"]  (4)
            (2) edge [pos=.35, "d"]  (5)
            (3) edge [in=-50,out=-130, looseness=12] (3)
            (3) edge ["e"]  (5)
            (3) edge [pos=.75, "f"]  (6);
        \end{tikzpicture}
    \end{document}
    

addendum: an alternative code, slightly shorter, using the positioning library:

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

\begin{document}
    \begin{tikzpicture}[
node distance = 11mm and 11mm,
   dot/.style = {circle, fill, inner sep=2pt, outer sep=0pt,
                 label=#1, node contents={}},
every edge quotes/.style = {auto=left, sloped, font=\scriptsize, inner sep=1pt}
                        ]
\node (1) [dot=above:1];
\node (2) [dot= left:2, below  left=of 1];
\node (3) [dot= left:3, below right=of 2];
\node (4) [dot=right:4,       right=of 3];
\node (5) [dot=right:5, above right=of 4];
\node (6) [dot=above:6, above  left=of 5];
%
\path   (1) edge [pos=.35, "a"] (4)
        (1) edge ["b"]  (2)
        (2) edge ["c"]  (4)
        (2) edge [pos=.35, "d"]  (5)
        (3) edge [in=-50,out=-130, looseness=12] (3)
        (3) edge ["e"]  (5)
        (3) edge [pos=.75, "f"]  (6);
    \end{tikzpicture}
\end{document}

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.