Comfortable Edge Labeling of Undirected Graph

Using GraphPlot and a custom EdgeRenderingFunction

ClearAll[erf];
erf[pos_List, lblcolors_, fontsizes_, linecolor_: Blue] := {linecolor, Line[#], 
 Sequence @@ Table[Inset[Style[Text[#3], lblcolors[[i]], FontSize -> fontsizes[[i]]], 
    pos[[i]] First@# + (1 - pos[[i]]) Last@#, Automatic, Automatic, -Subtract @@ Sort[#],
   Background -> White], {i, 1, Length@pos}]} &

Example:

edges = {{4 -> 2}, {5 -> 1}, {3 -> 2}, {2 -> 5}, {3 -> 5}};
labelededges = MapIndexed[{First@#1, ToString@First@#2} &, edges];

GraphPlot[labelededges, 
 EdgeRenderingFunction -> erf[{(5/6), 1/6}, {Green, Red}, {16, 24}],
 PlotStyle -> Thick, VertexLabeling -> True, ImagePadding -> 20]

enter image description here


You may:

Show@Table[
  CompleteGraph[3, 
   EdgeLabels -> {1 \[UndirectedEdge] 3 -> Placed[1, p]}, 
   ImagePadding -> 10], {p, {1/6, 1/2, 5/6}}]

enter image description here