I have the following graph, whose labels are generated in a for-loop:
\documentclass[tikz,margin=5mm]{standalone}
\usetikzlibrary{graphs,graphs.standard,quotes}
\usepackage{ifthen}
\begin{document}
\begin{tikzpicture}
\tikzstyle{vertex}=[circle,fill=blue!15,draw,minimum size=17pt,inner sep=0pt]
\graph[circular placement, radius=4cm, group polar shift=(360/5:0),
nodes={circle,draw,vertex}] {
\foreach \x [evaluate=\x as \sx using int(\x+1)] in {0,...,4} {
\foreach \y in {0,...,4} {
\x -- \y;
\x --["\ifthenelse{\sx<\y}{$\mathsf{alph}(w_{\sx} \cdots w_{\y})$}
{\ifthenelse{\sx=\y}{$\mathsf{alph}(w_{\sx})$}{}}", sloped] \y;
};
};
};
\end{tikzpicture}
\end{document}
The result is, that the labels
- cross the graphs edges
- overlap with other labels
The only thing I found out about this is, that automatic collision avoidance seems not to be available: Label automatically positioned so that it doesn't overlap anything.
Anyway, my example graph is not uncommon and somehow I should be able to place the labels in an acceptable way.
If there is no general way, what are possible solutions for this example?
I could think of the following positioning (including some resizing of the graph)
- place the labels of the outmost edges on the outside
- place the other labels in the pentagon in the middle
But I would not know how to achieve this.

\foreachloop, make a separate command for each one, and useposoption (as in[...,pos=.5]) to make sure none overlap. – Jānis Lazovskis Jul 06 '14 at 08:16