在 TikZ 中以优雅的方式更改路径的选项

在 TikZ 中以优雅的方式更改路径的选项

我正在构建一个有限状态自动机的图形。但是 F 到 C 的边缘似乎使图像的可读性降低。使用弯曲选项无法解决问题。有办法解决这个问题吗?我认为引入幻影节点可能是一种解决方案,但我不知道有任何选项可以通过该幻影节点生成边缘。

在此处输入图片描述

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning,automata}
\begin{document}
\begin{tikzpicture}[->,shorten >=1pt,auto,node distance=2cm,on grid,semithick,state/.style=state with output,every state/.style={draw=black!50,very thick,fill=black!20,scale=0.75}]
\node[state] (E) {$e$\nodepart{lower} $1$};
\node[state] (F) [right=of E] {$f$\nodepart{lower} $1$};
\node[state] (A) [below=of E] {$a$\nodepart{lower} $0$};
\node[state] (B) [below=of F] {$b$\nodepart{lower} $0$};
\node[state] (C) [below=of A] {$c$\nodepart{lower} $0$};
\node[state] (D) [below=of B] {$d$\nodepart{lower} $0$};
\path (A) edge[loop left] node {00} (A)
      edge[bend left] node {01} (B)
      edge[bend left] node {10} (C)
      (B) edge[bend left] node {00} (A)
      edge[loop right] node {01} (B)
      edge node {11} (F)
      (C) edge[bend left] node {00} (A)
      edge[loop left] node {10} (C)
      edge[bend left] node {11} (D)
      (D) edge node {00} (B)
      edge[bend left] node {10} (C)
      edge[loop right] node {11} (D)
      (E) edge node {00} (A)
      edge[loop left] node {01} (E)
      edge[bend left] node {11} (F)
      (F) edge[bend left] node {01} (E)
      edge[loop right] node {11} (F)
      edge node {10} (C);
\end{tikzpicture}
\end{document}

答案1

这就像 rpapa 的答案,但您不需要使用 fit 库。该解决方案与 一起使用current bounding box。我们知道bounding box添加路径时会更新。因此,我们可以使用最后一个边界框,更准确地说是最后一个东南角。

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning,automata}
\begin{document}
\begin{tikzpicture}[->,
                    shorten >=1pt,
                    auto,
                    node distance=2cm,
                    on grid,
                    semithick,state/.style=state with output,
                    every state/.style={draw=black!50,
                                        very thick,
                                        fill=black!20,
                                        scale=0.75}]
\node[state] (E) {$e$\nodepart{lower} $1$};
\node[state] (F) [right=of E] {$f$\nodepart{lower} $1$};
\node[state] (A) [below=of E] {$a$\nodepart{lower} $0$};
\node[state] (B) [below=of F] {$b$\nodepart{lower} $0$};
\node[state] (C) [below=of A] {$c$\nodepart{lower} $0$};
\node[state] (D) [below=of B] {$d$\nodepart{lower} $0$};
\path (A) edge[loop left] node {00} (A)
      edge[bend left] node {01} (B)
      edge[bend left] node {10} (C)
      (B) edge[bend left] node {00} (A)
      edge[loop right] node {01} (B)
      edge node {11} (F)
      (C) edge[bend left] node {00} (A)
      edge[loop left] node {10} (C)
      edge[bend left] node {11} (D)
      (D) edge node {00} (B)
      edge[bend left] node {10} (C)
      edge[loop right] node {11} (D)
      (E) edge node {00} (A)
      edge[loop left] node {01} (E)
      edge[bend left] node {11} (F)
      (F) edge[bend left] node {01} (E)
      edge[loop right] node {11} (F); 
 \draw (F) 
           to [out=45,in=45] (current bounding box.south east) 
           to [out=-135,in=-60] node[below,midway]{11} (C);   

\end{tikzpicture}
\end{document}

在此处输入图片描述

答案2

您可以适合节点并使用东南角绘制路径

\draw (F) to [out=45,in=45] (box.south east) to[out=-135,in=-45]  (C);  
\documentclass{文章}
\usepackage{tikz}
\usetikzlibrary{定位、自动机、适合}
\开始{文档}
\begin{tikzpicture}[->,缩短> = 1pt,自动,节点距离=2cm,在网格上,半厚,状态/.style=状态带输出,每个状态/.style={draw=black!50,非常厚,填充=黑色!20,比例=0.75}]
\node[state] (E) {$e$\nodepart{lower} $1$};
\node[state] (F) [right=of E] {$f$\nodepart{lower} $1$};
\node[state] (A) [below=of E] {$a$\nodepart{lower} $0$};
\node[state] (B) [below=of F] {$b$\nodepart{lower} $0$};
\node[state] (C) [below=of A] {$c$\nodepart{lower} $0$};
\node[state] (D) [below=of B] {$d$\nodepart{lower} $0$};



\path (A) 边[左循环] 节点 {00} (A)
      边[向左弯曲] 节点 {01} (B)
      边[向左弯曲] 节点 {10} (C)
      (B)边[向左弯曲] 节点 {00} (A)
      边[右循环] 节点 {01} (B)
      边缘节点 {11} (F)
      (C)边[向左弯曲] 节点 {00} (A)
      边[循环左] 节点 {10} (C)
      边[向左弯曲] 节点 {11} (D)
      (D)边缘节点{00}(B)
      边[向左弯曲] 节点[name=bas] {10} (C)
      边[环右] 节点[name=basdroit] {11} (D)
      (E)边缘节点{00}(A)
      边[环左] 节点 {01} (E)
      边[向左弯曲] 节点 {11} (F)
      (F)边 [向左弯曲] 节点 {01} (E)
      边[循环右] 节点 {11} (F);

\node[draw=red, fit=(E) (C) (F) (basdroit) (bas) ](box) {};  

  \draw (F) 到 [out=45,in=45] (box.south 东) 到[out=-135,in=-45] node[below,midway]{11} (C);   

\结束{tikzpicture}
\结束{文档}

适合节点和路径

相关内容