子图节点与常规 - tikz 重叠

子图节点与常规 - tikz 重叠

我希望拥有漂亮的状态机,而不必考虑它的布局。我还需要一些节点分组以及组描述。因此,我写了以下内容:

\documentclass{article}

\usepackage{tikz}

\usetikzlibrary{backgrounds, positioning, fit, graphdrawing, graphs, automata, shapes.geometric}
\usetikzlibrary{shapes, snakes, petri}
\usetikzlibrary{arrows, decorations.pathmorphing}
\usegdlibrary{trees, layered, force}

\begin{document}
\begin{tikzpicture}
  \graph[tree layout, grow' = right,
         nodes = {ellipse, draw}]
  {
    s -> {s1, s2, s3};
    s1 -> s1v2;
    s1v2 -> s1v1 ->[bend right] s1v2;
    s1v2 -> s1v3t;
    s2 -> s2v1 -> s2v2 ->[bend right] s2v1;
    s2v2 -> s2v3t;
    s2 -> s2v3 -> s2v2t;
    s3 -> s3v2 -> {s3v3t, s3v1t};
    NS1[draw, rectangle] // {s1v2, s1v1};
    NS2[draw, rectangle] // {s2v1, s2v2}
  };
\end{tikzpicture}
\end{document}

但是,子图节点与常规节点重叠。(如果您想亲自查看,请使用编译代码lualatex- 这是 TikZ 3 图形布局算法所必需的)。我认为这是在图形布局后创建它们的结果(请参阅pgf手册)。我该怎么办?

答案1

也许你可以放大sibling sep整个图表

\documentclass{article}

\usepackage{tikz}

\usetikzlibrary{backgrounds, positioning, fit, graphdrawing, graphs, automata, shapes.geometric}
\usetikzlibrary{shapes, snakes, petri}
\usetikzlibrary{arrows, decorations.pathmorphing}
\usegdlibrary{trees, layered, force}

\begin{document}
\begin{tikzpicture}
  \graph[tree layout, grow' = right,
         nodes = {ellipse, draw},
         sibling sep=3em,% enlarge the sibling sep to 3em
        ]
  {
    s -> {s1, s2, s3};
    s1 -> s1v2;
    s1v2 -> s1v1 ->[bend right] s1v2;
    s1v2 -> s1v3t;
    s2 -> s2v1 -> s2v2 ->[bend right] s2v1;
    s2v2 -> s2v3t;
    s2 -> s2v3 -> s2v2t;
    s3 -> s3v2 -> {s3v3t, s3v1t};
    NS1[draw, rectangle] // {s1v2, s1v1};
    NS2[draw, rectangle] // {s2v1, s2v2}
  };
\end{tikzpicture}
\end{document}

在此处输入图片描述

或仅适用于s1v3t

\documentclass{article}

\usepackage{tikz}

\usetikzlibrary{backgrounds, positioning, fit, graphdrawing, graphs, automata, shapes.geometric}
\usetikzlibrary{shapes, snakes, petri}
\usetikzlibrary{arrows, decorations.pathmorphing}
\usegdlibrary{trees, layered, force}

\begin{document}
\begin{tikzpicture}
  \graph[tree layout, grow' = right,
         nodes = {ellipse, draw},
        ]
  {
    s -> {s1, s2, s3};
    s1 -> s1v2;
    s1v2 -> s1v1 ->[bend right] s1v2;
    {[sibling sep=6em]s1v2 -> s1v3t};% enlarge sibling sep
    s2 -> s2v1 -> s2v2 ->[bend right] s2v1;
    s2v2 -> s2v3t;
    s2 -> s2v3 -> s2v2t;
    s3 -> s3v2 -> {s3v3t, s3v1t};
    NS1[draw, rectangle] // {s1v2, s1v1};
    NS2[draw, rectangle] // {s2v1, s2v2};
  };
\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容