2

Consider following graph

%! TEX program = lualatex
\documentclass{article}
\usepackage{tikz}
\usepackage[graphics, active, tightpage]{preview}
\PreviewEnvironment{tikzpicture}

\usetikzlibrary{graphs,graphdrawing}
\usegdlibrary{trees, layered, circular, routing}

\begin{document}
\begin{tikzpicture}
  \graph [layered layout, head anchor=north, tail anchor=south] {

    { [edge={draw=none}] 12 -> 6 -> 4 -> 3 -> 2}; 
    { [same layer] 12, a/17 },
    { [same layer] 6, b/16,c/14,d/15 },
    { [same layer] 4, e/9 },
    { [same layer] 3, f/13 },
    { [same layer] 2, g/2, h/5 },

    a --[bend right=0] { b --[bend right=0] {f[nudge right=7mm],g[nudge right=1.5mm]}, c --[bend right=0] f, c--[bend right=0] h, d --[bend right=0] {f,h}, e[nudge right=25mm] --[bend right=0] {g,h}};

  };
  % ADD MANUALLY PARALLEL EDGE:
  \draw ([xshift=2pt]e.south) -- ([xshift=2pt]h.north);
\end{tikzpicture}
\end{document}

enter image description here

I have attached to all visible edges the property bend right=0.

I want to avoid to set this for each edge individually but adjust it for all edges of this graph.

How can I do this?

see also related question: Why is this edge not straight when using subgraphs in layered layout?

Hotschke
  • 5,300
  • 5
  • 33
  • 63

1 Answers1

3

Specify only bend right on the edges, then add bend angle=0 to the options of the tikzpicture. (Or use \begin{scope}[bend angle=0] <graph> \end{scope}.)

Or you can specify nothing for the individual edges, and add edges={bend right=0} to the options of the graph.

enter image description here

%! TEX program = lualatex
\documentclass{article}
\usepackage{tikz}

\usetikzlibrary{graphs,graphdrawing}
\usegdlibrary{trees, layered, circular, routing}

\begin{document}
\begin{tikzpicture}[bend angle=0]
  \graph [layered layout, head anchor=north, tail anchor=south] {

    { [edge={draw=none}] 12 -> 6 -> 4 -> 3 -> 2}; 
    { [same layer] 12, a/17 },
    { [same layer] 6, b/16,c/14,d/15 },
    { [same layer] 4, e/9 },
    { [same layer] 3, f/13 },
    { [same layer] 2, g/2, h/5 },

    a --[bend right] { b --[bend right] {f[nudge right=7mm],g[nudge right=1.5mm]}, c --[bend right] f, c--[bend right] h, d --[bend right] {f,h}, e[nudge right=25mm] --[bend right] {g,h}};

  };
  % ADD MANUALLY PARALLEL EDGE:
  \draw ([xshift=2pt]e.south) -- ([xshift=2pt]h.north);
\end{tikzpicture}

\begin{tikzpicture}
  \graph [layered layout, head anchor=north, tail anchor=south,
          edges={bend right=0} % <-- added this one
          ] {

    { [edge={draw=none}] 12 -> 6 -> 4 -> 3 -> 2}; 
    { [same layer] 12, a/17 },
    { [same layer] 6, b/16,c/14,d/15 },
    { [same layer] 4, e/9 },
    { [same layer] 3, f/13 },
    { [same layer] 2, g/2, h/5 },

    a -- { b -- {f[nudge right=7mm],g[nudge right=1.5mm]}, c -- f, c-- h, d -- {f,h}, e[nudge right=25mm] -- {g,h}};

  };
  % ADD MANUALLY PARALLEL EDGE:
  \draw ([xshift=2pt]e.south) -- ([xshift=2pt]h.north);
\end{tikzpicture}
\end{document}
Torbjørn T.
  • 206,688