TikZ 3.0:如何“缩放”图形布局?

TikZ 3.0:如何“缩放”图形布局?

我有这个状态机:

\documentclass{standalone}

\usepackage{tikz}

\usetikzlibrary{arrows.meta, graphs, graphdrawing, quotes, automata}
\usegdlibrary{circular}

\begin{document}
\tikz[>=stealth, shorten >=1pt] {
  \graph[simple necklace layout, nodes = {state}, node sep = 1cm, grow=right] {
    a[initial, initial text={}],
    b, c, d[accepting], e, f,
    a
    ->["$a$"] f
    ->[loop above, "$a$"] f
    ->[bend left, "$b$"] e
    ->[bend left, "$a$"] f,
    e
    -> ["$b$"] d
    -> ["$a, b$", loop right] d,
    c
    ->["$b$"] d,
    c
    ->["$a$", bend left] b
    ->["$a$", loop below] b
    ->["$b$", bend left] c,
    a
    ->["$b$"] b
    ;
  }
}
\end{document}

自动贩卖机

我想“压平”图形布局,使其变成椭圆形,但不缩放整个图片(因为这会弄乱一切)。有办法吗?

答案1

可以通过选项移动节点yshift。节点fe向下和b向上移动c

\documentclass{standalone}

\usepackage{tikz}

\usetikzlibrary{arrows.meta, graphs, graphdrawing, quotes, automata}
\usegdlibrary{circular}

\begin{document}
\tikz[>=stealth, shorten >=1pt] {
  \graph[simple necklace layout, nodes = {state}, node sep = 1cm,
grow=right] {
    a[initial, initial text={}],
    b[yshift=5mm], c[yshift=5mm], d[accepting],
    e[yshift=-5mm], f[yshift=-5mm],
    a
    ->["$a$"] f
    ->[loop above, "$a$"] f
    ->[bend left, "$b$"] e
    ->[bend left, "$a$"] f,
    e
    -> ["$b$"] d
    -> ["$a, b$", loop right] d,
    c
    ->["$b$"] d,
    c
    ->["$a$", bend left] b
    ->["$a$", loop below] b
    ->["$b$", bend left] c,
    a
    ->["$b$"] b
    ;
  }
}
\end{document}

结果

或者使用一些间隔更均匀的节点:

\documentclass{standalone}

\usepackage{tikz}

\usetikzlibrary{arrows.meta, graphs, graphdrawing, quotes, automata}
\usegdlibrary{circular}

\begin{document}
\tikz[>=stealth, shorten >=1pt] {
  \graph[simple necklace layout, nodes = {state}, node sep = 1cm,
grow=right] {
    a[initial, initial text={}],
    b[yshift=5mm, xshift=1.5mm], c[yshift=5mm, xshift=-1.5mm],
    d[accepting],
    e[yshift=-5mm, xshift=-1.5mm], f[yshift=-5mm, xshift=1.5mm],
    a
    ->["$a$"] f
    ->[loop above, "$a$"] f
    ->[bend left, "$b$"] e
    ->[bend left, "$a$"] f,
    e
    -> ["$b$"] d
    -> ["$a, b$", loop right] d,
    c
    ->["$b$"] d,
    c
    ->["$a$", bend left] b
    ->["$a$", loop below] b
    ->["$b$", bend left] c,
    a
    ->["$b$"] b
    ;
  }
}
\end{document}

结果

答案2

对于这种情况,我能够使用 找到解决方法layered layout

\documentclass{standalone}

\usepackage{tikz}

\usetikzlibrary{arrows.meta, graphs, graphdrawing, quotes, automata}
\usegdlibrary{layered}


\begin{document}
\tikz[>=stealth, shorten >=1pt] {
  \graph[layered layout, nodes = {state}, level sep = 1cm, sibling
  distance = 2cm, grow=right] {
    a[initial, initial text={}] -!- {
      b -!- {
        c
      },
      f -!- {
        e
      }
    } -!-
    d[accepting],

    a
    ->["$a$"] f
    ->[loop above, "$a$"] f
    ->[bend left, "$b$"] e
    ->[bend left, "$a$"] f,
    e
    -> ["$b$"] d
    -> ["$a, b$", loop right] d,
    c
    ->["$b$"] d,
    c
    ->["$a$", bend left] b
    ->["$a$", loop below] b
    ->["$b$", bend left] c,
    a
    ->["$b$"] b
    ;
  }
}
\end{document}

在此处输入图片描述

但是,如果顶点数为奇数,这会更加棘手。此外,这种布局不允许我直接控制节点距离。但我很满意。

相关内容