tikz,自动机,强制自循环的大小相同

tikz,自动机,强制自循环的大小相同

在下面使用 tikz 自动机库的图片上,我希望所有自循环都具有相同的大小(即附加到标记为 1 的最右下节点的自循环的大小)。

但目前自环的大小取决于节点的大小以及自环的方向。

\documentclass{article}
\usepackage{tikz} \usetikzlibrary{arrows,automata}
\usepackage{pifont}

\begin{document}

\tikzset{every state/.style={draw,rectangle,rounded corners=2pt,inner sep=2pt,minimum width=12pt,minimum height=12pt}}
\begin{tikzpicture}
\begin{scope}[->,>=stealth',shorten >=1pt,auto,semithick]
\node[state,accepting] (1) at (1.5,1.5) {\ding{189}\ding{172}};
\node[state,accepting] (2) at (1.5,3.0) {\ding{188}\ding{173}\ding{172}};
\node[state,accepting] (3) at (1.5,4.5) {\ding{177}\ding{176}\ding{173}\ding{172}};
\node[state,accepting] (4) at (3.0,4.5) {\ding{176}\ding{173}\ding{172}};
\node[state,accepting] (5) at (3.0,3.0) {\ding{175}\ding{174}\ding{172}};
\node[state,accepting] (6) at (4.5,3.0) {\ding{174}\ding{172}};
\node[state,accepting] (7) at (3.0,1.5) {\ding{173}\ding{172}};
\node[state,accepting] (8) at (4.5,1.5) {\ding{172}};
\draw[<-] (8.south east) -- node[sloped] {} ++(2.3mm,-2.3mm);
\node[state,accepting,color=gray] (14) at (1.5,0.0) {\ding{174}\ding{172}};
\node[state,accepting,color=gray] (15) at (3.0,6.0) {\ding{188}\ding{173}\ding{172}};
\node[state,accepting,color=gray] (16) at (4.5,0.0) {\ding{188}\ding{173}\ding{172}};
\node[state,accepting,color=gray] (17) at (4.5,4.5) {\ding{172}};
\path
(1) edge [in=-150,out=-120,loop] node[below] {.} (1)
(1) edge[bend angle=70,bend right] node[below=0,sloped] {.} (8)
(1) edge node[below=0,sloped] {.} (7)
(1) edge[densely dotted] node[below=0,sloped] {.} (14)
(2) edge [loop left] node {.} (2)
(2) edge node[below=0,sloped] {.} (5)
(3) edge [in=120,out=150,loop] node[above] {.} (3)
(3) edge[bend angle=70,bend right] node[below=0,sloped] {.} (1)
(3) edge node[below=0,sloped] {.} (2)
(3) edge[bend angle=16,bend right] node[below=0,sloped] {.} (5)
(4) edge[densely dotted] node[below=0,sloped] {.} (17)
(4) edge[densely dotted] node[below=0,sloped] {.} (15)
(4) edge node[below=0,sloped] {.} (5)
(5) edge node[below=0,sloped] {.} (8)
(5) edge node[below=0,sloped] {.} (3)
(5) edge node[below=0,sloped] {.} (6)
(6) edge[bend angle=18,bend right] node[below=0,sloped] {.} (8)
(6) edge node[below=0,sloped] {.} (4)
(6) edge [loop right] node {.} (6)
(7) edge node[below=0,sloped] {.} (8)
(7) edge [loop below] node {.} (7)
(7) edge node[above=0,sloped] {.} (5)
(8) edge [loop right] node {.} (8)
(8) edge[bend angle=18,bend left] node[below=0,sloped] {.} (7)
(8) edge node[below=0,sloped] {.} (6)
(16) edge[densely dotted] node[below=0,sloped] {.} (8);
\end{scope}
\end{tikzpicture}

\end{document}

在此处输入图片描述

答案1

也许这是朝着正确的方向发展的。循环是通过图片完成的,因为破解边缘路径有点困难。(我还将节点的定位从手动更改为矩阵。可以进一步简化这一点,但我想保留节点名称。)

\documentclass{article}
\usepackage{tikz} 
\usetikzlibrary{matrix,arrows,automata,calc}
\usepackage{pifont}
\tikzset{pics/sloped loop/.style={code={
    \def\pv##1{\pgfkeysvalueof{/tikz/sloped loop parameters/##1}}
    \tikzset{/tikz/sloped loop parameters/.cd,#1}
    \draw[/tikz/sloped loop parameters/style,pic actions]
    (\pv{node}.\pv{angle}+\pv{opening angle}) 
    to[out=\pv{angle}+\pv{opening angle},in=\pv{angle}+90]
     ($(\pv{node}.\pv{angle})+(\pv{angle}:\pv{distance})$) coordinate(aux)
    to[out=\pv{angle}-90,in=\pv{angle}-\pv{opening angle}]
     (\pv{node}.\pv{angle}-\pv{opening angle});}},
sloped loop parameters/.cd,node/.initial=A,
opening angle/.initial=15,style/.initial={->},
set/.code={\typeout{set #1}\tikzset{slope loop parameters/.cd,#1}},
angle/.initial=90,distance/.initial=0.5cm}
\begin{document}

\tikzset{every state/.style={draw,rectangle,rounded corners=2pt,inner sep=2pt,minimum width=12pt,minimum height=12pt}}
\begin{tikzpicture}[]
\matrix[nodes={state,accepting},column sep=1cm,row sep=1cm]
{
& \node[color=gray] (15)  {\ding{188}\ding{173}\ding{172}}; & \\
\node (3) {\ding{177}\ding{176}\ding{173}\ding{172}}; &
\node (4) {\ding{176}\ding{173}\ding{172}}; &
\node[color=gray] (17) {\ding{172}}; \\
\node (2) {\ding{188}\ding{173}\ding{172}}; &
\node (5) {\ding{175}\ding{174}\ding{172}}; &
\node (6) {\ding{174}\ding{172}}; \\
\node (1) {\ding{189}\ding{172}}; &
\node (7) {\ding{173}\ding{172}}; &
\node (8) {\ding{172}}; \\
\node[color=gray] (14)  {\ding{174}\ding{172}}; & &
\node[color=gray] (16)  {\ding{188}\ding{173}\ding{172}};\\
};
\begin{scope}[->,>=stealth',shorten >=1pt,auto,semithick]
%\node[state,accepting] (1) at (1.5,1.5) {\ding{189}\ding{172}};
%\node[state,accepting] (2) at (1.5,3.0) {\ding{188}\ding{173}\ding{172}};
%\node[state,accepting] (3) at (1.5,4.5) {\ding{177}\ding{176}\ding{173}\ding{172}};
%\node[state,accepting] (4) at (3.0,4.5) {\ding{176}\ding{173}\ding{172}};
%\node[state,accepting] (5) at (3.0,3.0) {\ding{175}\ding{174}\ding{172}};
%\node[state,accepting] (6) at (4.5,3.0) {\ding{174}\ding{172}};
%\node[state,accepting] (7) at (3.0,1.5) {\ding{173}\ding{172}};
%\node[state,accepting] (8) at (4.5,1.5) {\ding{172}};
\draw[<-] (8.south east) -- node[sloped] {} ++(2.3mm,-2.3mm);
%\node[state,accepting,color=gray] (14) at (1.5,0.0) {\ding{174}\ding{172}};
%\node[state,accepting,color=gray] (15) at (3.0,6.0) {\ding{188}\ding{173}\ding{172}};
%\node[state,accepting,color=gray] (16) at (4.5,0.0) {\ding{188}\ding{173}\ding{172}};
%\node[state,accepting,color=gray] (17) at (4.5,4.5) {\ding{172}};
\path
pic{sloped loop={node=1,angle=-135}} (aux) node[below] {.}
%(1) edge [in=-150,out=-120,loop] node[below] {.} (1)
(1) edge[bend angle=70,bend right] node[below=0,sloped] {.} (8)
(1) edge node[below=0,sloped] {.} (7)
(1) edge[densely dotted] node[below=0,sloped] {.} (14)
pic{sloped loop={node=2,angle=180}} (aux) node[left] {.}
%(2) edge [loop left] node {.} (2)
(2) edge node[below=0,sloped] {.} (5)
pic{sloped loop={node=3,angle=135}} (aux) node[above] {.}
%(3) edge [in=120,out=150,loop] node[above] {.} (3)
(3) edge[bend angle=70,bend right] node[below=0,sloped] {.} (1)
(3) edge node[below=0,sloped] {.} (2)
(3) edge[bend angle=16,bend right] node[below=0,sloped] {.} (5)
(4) edge[densely dotted] node[below=0,sloped] {.} (17)
(4) edge[densely dotted] node[below=0,sloped] {.} (15)
(4) edge node[below=0,sloped] {.} (5)
(5) edge node[below=0,sloped] {.} (8)
(5) edge node[below=0,sloped] {.} (3)
(5) edge node[below=0,sloped] {.} (6)
(6) edge[bend angle=18,bend right] node[below=0,sloped] {.} (8)
(6) edge node[below=0,sloped] {.} (4)
pic{sloped loop={node=6,angle=0}} (aux) node[right] {.}
%(6) edge [loop right] node {.} (6)
(7) edge node[below=0,sloped] {.} (8)
pic{sloped loop={node=7,angle=-90}} (aux) node[below] {.}
%(7) edge [loop below] node {.} (7)
(7) edge node[above=0,sloped] {.} (5)
pic{sloped loop={node=8,angle=0}} (aux) node[right] {.}
%(8) edge [loop right] node {.} (8)
(8) edge[bend angle=18,bend left] node[below=0,sloped] {.} (7)
(8) edge node[below=0,sloped] {.} (6)
(16) edge[densely dotted] node[below=0,sloped] {.} (8);
\end{scope}
\end{tikzpicture}

\end{document}

在此处输入图片描述

相关内容