如何为 tikz 图中的所有边设置弯曲右 = 0?

如何为 tikz 图中的所有边设置弯曲右 = 0?

考虑下面的图表

%! 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}

在此处输入图片描述

我已将该属性附加到所有可见边缘bend right=0

我想避免为每个边单独设置它,而是针对该图的所有边进行调整。

我怎样才能做到这一点?

另请参阅相关问题:为什么在分层布局中使用子图时,这个边不直?

答案1

bend right在边缘上指定,然后添加bend angle=0到 的选项中tikzpicture。(或使用\begin{scope}[bend angle=0] <graph> \end{scope}。)

或者您可以不为各个边指定任何内容,而将其添加edges={bend right=0}到图形的选项中。

在此处输入图片描述

%! 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}

相关内容