当我使用以下方法微调两个状态之间的边缘位置时,我遇到了一种奇怪的情况\usetikzlibrary{自动机}。
一个例子:
\begin{tikzpicture}
\tikzstyle{every node}=[font=\tiny]
[
initial/.style={line width=1pt},
accepting by double/.append style={line width=1pt},
semithick,
]
\draw node (a) [state] at (3, 1) {\footnotesize $a$};
\draw node (b) [state] at (3, -1) {\footnotesize $b$};
\path[->] (a) edge [in=120,out=240,looseness=0] node[sloped] {>} (b);
\path[->] (a) edge [in=100,out=260,looseness=0] node[sloped] {>} (b);
\path[->] (a) edge [in=80,out=280,looseness=0] node[sloped] {>} (b);
\path[->] (a) edge [in=60,out=300,looseness=0] node[sloped] {>} (b);
\end{tikzpicture}
这是使用 LaTeXiT 的输出,其中第二和第四个边缘的文本是向后显示的。
更有趣的是 pdflatex 生成了不同但仍然不可预测的文本:
答案1
为了获得可预测的“文本”,请不要以这种复杂的方式绘制直线。如果您想从某个节点以某个角度开始,则不必使用out=...,in=...
,只需在起始节点和目标中指定角度即可。
\documentclass[border=3.14mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{automata,quotes}
\begin{document}
\begin{tikzpicture}[
initial/.style={line width=1pt},
accepting by double/.append style={line width=1pt},
semithick,
]
\tikzset{every node/.style={font=\tiny}}
\draw node (a) [state] at (3, 1) {\footnotesize $a$};
\draw node (b) [state] at (3, -1) {\footnotesize $b$};
\path[->] (a.240) edge[">",sloped,pos=0.3] (b.120);
\path[->] (a.260) edge[">",sloped,pos=0.3] (b.100);
\path[->] (a.280) edge[">",sloped,pos=0.3] (b.80);
\path[->] (a.300) edge[">",sloped,pos=0.3] (b.60);
\end{tikzpicture}
\end{document}
这给出了可靠且可预测的结果。
获得结果的另一种方法是
\documentclass[border=3.14mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{automata}
\begin{document}
\begin{tikzpicture}[
initial/.style={line width=1pt},
accepting by double/.append style={line width=1pt},
semithick,
]
\tikzset{every node/.style={font=\tiny}}
\draw node (a) [state] at (3, 1) {\footnotesize $a$};
\draw node (b) [state] at (3, -1) {\footnotesize $b$};
\draw[->] (a.240) -- (b.120) node[midway,sloped] {>};
\draw[->] (a.260) -- (b.100) node[midway,sloped] {>};
\draw[->] (a.280) -- (b.80) node[midway,sloped] {>};
\draw[->] (a.300) -- (b.60) node[midway,sloped] {>};
\end{tikzpicture}
\end{document}
不依赖于quotes
。为什么会发生这种情况? Ti钾Z 是由欧洲人写的,因此文本从左向右流动。因此,如果路径以比其x
开始时更大的坐标结束,则文本方向与路径以比其x
开始时更小的坐标结束时的方向相反。到目前为止,一切都是可以预测的。当线条垂直时,您发现的是奇怪的效果,其中 Ti钾Z 必须做出临时选择,并且由于线条构造为松散度=0 的曲线,因此出现了舍入误差。然而,这些舍入误差似乎并不局限于这种情况。
\documentclass[tikz,border=3.14mm]{standalone}
\usetikzlibrary{automata}
\begin{document}
\tikzset{every node/.style={font=\tiny}}
\foreach \X in {0,5,...,355}
{\pgfmathsetmacro{\Y}{90+2*sin(\X)}
\begin{tikzpicture}[
initial/.style={line width=1pt},
accepting by double/.append style={line width=1pt},
semithick,
]
\path[use as bounding box] (2,-2) rectangle (4,2);
\draw node (a) [state] at (3, 1) {\footnotesize $a$};
\node[anchor=west] at (3.2,0) {\Y};
\node[anchor=east] at (2.8,0) {\X};
\draw node (b) [state] at (3, -1) {\footnotesize $\X$};
\draw[->] (a.270) -- (b.\Y) node[midway,sloped] {>};
\end{tikzpicture}}
\end{document}