[Tex/LaTex] tkz-graph : inconsistency between edge and loop

diagramstikz-pgftkz-collection

I'm discovering the great package tkz-graph and I am experiencing some trouble with the \Loop macro.

There seem to be some inconsistencies between the \Loop macro and the \Edge macro.
For example, in the following document, the labels of the edges are not placed in the same way.
First, the loop has an array but the edge does not.
Second, the syntax \( \) for math-mode works only in the case of the loop.

\documentclass{minimal}
\usepackage{fixltx2e}
\usepackage{tkz-graph}
\begin{document}
\begin{tikzpicture}[scale=1]
  \Vertex{A}
  \Vertex[x=2,y=0]{B}
  \Loop[dist=1.5cm,dir=WE,label=\(x\)](A)
  \Edges[label=$y$](A,B)
\end{tikzpicture}
\end{document}

Third, the macro \tikzset{EdgeStyle/.append style = …}doesn't work for loops and I did not find a solution in the user manual. For example, \tikzset{EdgeStyle/.append style ={->}} doesn't use the same arrow tip for the edge and for the loop.

Finally, the use of style={->} produces different results in the loop than in the edge (the path is thicker in the latter). Here is the output from the code above, but with \tikzset{EdgeStyle/.append style ={->}}:
Edge and loop have different styles

Best Answer

Sorry for the french documentation but with the next version I will try to write a english version. The question is about tkz-graphand not tkz-bergeand tkz-bergehas an english doc !!

A last detail before my answer, I'm not happy about the options(styles) of these packages because I wrote them with xkeyval and it's difficult to get the same options than Tikz. I will write the next version with pgfkeys.

Now the problem appears because there are a lot of method to change the styles. EdgeStyleis used to modify a global style for edges, LoopStyle is a global style for loops and style is local; Loop first looks at EdgeStyle, then at LoopStyle and at the end applies a local style if this style exists. For the labels, you have LabelStyle and then labelstyle

The code is

\def\tkzGR@loop[#1](#2){%
\setkeys[GR]{loop}{#1}%
\protected@edef\@tempa{%
\noexpand \draw[\cmdGR@loop@color] (#2)%
  edge [EdgeStyle,LoopStyle,\cmdGR@loop@style]%
  node [LabelStyle,\cmdGR@loop@labelstyle]%
  {\cmdGR@loop@label} (#2)}\@tempa;%
}%

A possible solution is

\documentclass{minimal}
\usepackage{fixltx2e}
\usepackage{tkz-berge}

\tikzset{LabelStyle/.style= {fill=yellow}}

\begin{document}
\begin{tikzpicture}[scale=1]
  \Vertex{A}
  \Vertex[x=2,y=0]{B}     
  \Loop[dist=1.5cm,dir=WE,label=\(x\),
        labelstyle={left=12pt,color=red,fill=white,draw}](A)
  \Edges[label=$y$](A,B)
\end{tikzpicture}
\end{document} 

enter image description here I agree if you find the styles unclear or confused but I will make something better with pgfkeysin the next version. I need to make the versions compatible because tkz-graph is used by lot of people.

The first solution of Count Zero is fine too

Update : Another solution is to define a personal style and to use only Tikzto draw the loops. It's always possible to use tikz.