[Tex/LaTex] Tikz edge label position

graphslabelstikz-pgf

Is there a way to set the location of the position of edge label when using the tikz graph package?

I attempted to look for samples of this being done in the manual, but was unable to find any (closest I got was in 19.6 where it shows how to set some options for individual edges).

Is this possible?

Edit: more specifically, I am looking for a way to put the label above or below the edge.

Edit to add MWE:

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{graphdrawing,positioning,graphs}
\usegdlibrary{layered, trees}
\begin{document}
\begin{tikzpicture}
    \begin{graph}
     {1->[edge label=hello]2};
    \end{graph}
\end{tikzpicture}

\end{document}

Best Answer

The labels seem to be placed with the auto option enabled, which places the node/label on the side of the line, in your MWE above it. As such you can add the swap option to move the label to the other side.

enter image description here

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{graphdrawing,positioning,graphs}
\usegdlibrary{layered, trees}
\begin{document}
\begin{tikzpicture}
    \begin{graph}
     {1 -> [edge label=hello]
      2 -> [edge label=hello,swap]
      3};
    \end{graph}
\end{tikzpicture}
\end{document}
Related Question