6

Using tkz-graph package I often feel the need to move a little bit the labels on the edges, that are always positioned midway the edge. In this example I would move the label 0.5 from node a to node d closer to node d to avoid intersection with a red box. Here a MWE:

\documentclass[border=10pt]{standalone}
\usepackage{tkz-graph}
\usetikzlibrary{fit}
\thispagestyle{empty}
\begin{document}
    \begin{tikzpicture}
        \GraphInit[vstyle=Normal]
        \SetGraphUnit{1.5}
        \Vertices{circle}{a,b,c,d,e}
        \Edge[label=1](a)(b)
        \Edge[label=2](a)(c)
        \Edge[label=0.5](a)(d)
        \Edge[label=3](a)(e)
        \node[draw=red!50,rounded corners=5mm,fit=(b.north) (a.south) (c.west) (a.east)](BORD) {};
    \node[right of=BORD,anchor=west,inner sep=1cm]{$\mathcal{G}$};
    \end{tikzpicture}
\end{document}

This is the result: tikzgraph example

How to mode the 0.5 label along the edge and not always in the center?

5
  • 3
    \Edge[label=0.5,style={pos=.4}](a)(d)? Jul 29, 2016 at 11:03
  • So simple! You saved my day!
    – linello
    Jul 29, 2016 at 12:55
  • @linello What font did you use for this example? Jul 31, 2016 at 15:54
  • It's the font used in the arsclassica package, an addition to the classicthesis font. I think it's a Palatino based font family.
    – linello
    Aug 1, 2016 at 10:09
  • The the font of the $G$ it's Euler, still in the arsclassica package.
    – linello
    Aug 1, 2016 at 10:16

1 Answer 1

7

The \Edge macro is only syntactic sugar for basic TikZ which draw a path and places a node on it. Nodes on paths can receive the pos key to indicate at what fraction the node is to be placed. To set node option in \Edge you have to wrap them in the style option, i.e.

\Edge[label=0.5,style={pos=.3}](a)(d)

to place the node at one third of the path starting from (a). For your example I chose pos=.25.

\documentclass[border=10pt]{standalone}
\usepackage{tkz-graph}
\usetikzlibrary{fit}
\begin{document}
\begin{tikzpicture}
  \GraphInit[vstyle=Normal]
  \SetGraphUnit{1.5}
  \Vertices{circle}{a,b,c,d,e}
  \Edge[label=1](a)(b)
  \Edge[label=2](a)(c)
  \Edge[label=0.5,style={pos=.25}](a)(d)
  \Edge[label=3](a)(e)
  \node[draw=red!50,rounded corners=5mm,fit=(b.north) (a.south) (c.west) (a.east)](BORD) {};
  \node[right of=BORD,anchor=west,inner sep=1cm]{$\mathcal{G}$};
\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.