如何使边缘平行

如何使边缘平行

如何使顶点 {q_1,q_3} 和 {q_1,q_2,q_3} 之间的边平行?

代码:

\documentclass[tikz,12pt,border=1mm]{standalone}
\usepackage[brazil]{babel}
\usepackage{tkz-euclide}
\usepackage{amssymb}
\usetikzlibrary{automata, positioning, arrows}


\tikzset{->,
>=stealth,
node distance = 3cm,
every state/.style={thick, fill=gray!10},
initial text = $I$,
auto rotate/.style={auto=right,->,
    to path={let \p1=(\tikztostart),\p2=(\tikztotarget),
        \n1={atan2(\y2-\y1,\x2-\x1)},\n2={\n1-10},\n3={\n1+190}
        in (\tikztostart.\n2) -- (\tikztotarget.\n3) \tikztonodes}}}


\begin{document}
\begin{tikzpicture}[
->, >=stealth,
node distance=3cm,
every state/.style={thick, fill=gray!10},
initial text={$I$},
]

\node[xscale=2, transform shape,state,accepting] (Q2) at (6.5,-3) {%
    \scalebox{0.5}[1]{$\{q_1,q_2,q_3\}$}};
\node[xscale=2, transform shape,state] (Q4) at (3,-3) {%
    \scalebox{0.5}[1]{$\{q_1,q_3\}$}};

\draw (Q2) edge [auto rotate, above] node [pos = 0.5] {$b$} (Q4);
\draw (Q4) edge [auto rotate, below] node [pos = 0.5] {$a$} (Q2);
\end{tikzpicture}
\end{document}

输出:

在此处输入图片描述

答案1

一个快速的解决方法是更改​​以下几行

\draw (Q2) edge [auto rotate, above] node [pos = 0.5] {$b$} (Q4);
\draw (Q4) edge [auto rotate, below] node [pos = 0.5] {$a$} (Q2);

\draw (Q2) [transform canvas={yshift=1mm}, shorten <=-0.25pt, shorten >=-0.5pt] edge node [above, pos = 0.5] {$b$} (Q4);
\draw (Q4) [transform canvas={yshift=-1mm}, shorten <=-0.25pt, shorten >=-0.5pt] edge node [below, pos = 0.5] {$a$} (Q2);

为了使线保持水平。transform canvas偏移原始元素,而shorten根据参数延伸/收缩提示。

在此处输入图片描述

相关内容