[pgf-tikz] Creating directed graphs with edge labels

Henri Menke henrimenke at gmail.com
Wed Mar 4 23:45:58 CET 2020


You can draw a similar graph in TikZ as well, but there edge labels also do
not take part in the positioning algorithm, so overlaps have to be avoided
manually.

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{graphs,graphdrawing,quotes}
\usegdlibrary{layered}
\begin{document}
\begin{tikzpicture}
    \graph[layered layout, sibling distance=3cm, level distance=3cm] {
        A ->[loop,"a very long label"] A,
        A ->[loop,min distance=4cm,"a very long label"] A,
        A ->["a long label" sloped] B,
        A ->["a long label" sloped] C,
        A ->["a long label" sloped] D,
    };
\end{tikzpicture}
\end{document}

I don't know much about graphdrawing (I'm only the maintainer, not the
implementer) but I think there are no algorithm that take the labels into
accout.

Cheers, Henri

On 3/5/20 10:05 AM, Eric Gorr wrote:
> I would like to create a directed graph with edge labels with the following
> properties:
> 
>    1. edge labels do not overlap with each other
>    2. edge labels do not overlap edges
>    3. edge labels are drawn along the edge.
> 
> For example, I can use the following graphviz graph
> 
> digraph G {    splines=line;    rankdir=LR;    A -> B [label="a long
> label"];    A -> C [label="a long label"];    A -> A [label="a very
> long label"];    A -> A [label="a very long label"];    A -> D
> [label="a long label"];}
> 
> to generate https://i.stack.imgur.com/34uVM.png
> 
> However, it does not seem possible to obtain a graph with edge labels with
> the three properties.
> 
> Is creating a graph like this using PGF TIKZ possible? If so, any examples
> for how to do so would be helpful.
> 
> Thank you.
> 


More information about the pgf-tikz mailing list.