오토마타 다이어그램을 더욱 좋게 만들기

오토마타 다이어그램을 더욱 좋게 만들기

tikz 라이브러리를 사용하여 자동 장치를 그렸습니다.오토마타. 다이어그램을 다듬는 데 도움이 필요합니다. 나는 할 수 없습니다 :

  1. 가장자리 레이블(kr, ur 등)을 정확히 두 노드 사이를 의미하는 중앙에 정렬합니다.
  2. 가장자리 라벨과 가장자리 사이에 동일한 간격 만들기
  3. 다이어그램을 더욱 예쁘게 만들어보세요 :) ;)

LaTeX 코드는 다음과 같습니다.

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning}
\usetikzlibrary{automata}
\begin{document}
\begin{tikzpicture}[shorten >=1pt,node distance=2cm,on grid]
\node[state,initial] (q_0) {$q_0$};
\node[state] (q_1) [above right=of q_0] {$q_1$};
\node[state] (q_2) [below right=of q_0] {$q_2$};
\node[state,accepting] (q_3) [right=of q_1] {$q_3$};
\node[state] (q_4) [right=of q_2] {$q_4$};
\node[state] (q_5) [right=of q_4] {$q_5$};
\node[state,accepting] (q_6) [right=of q_5] {$q_6$};
\path[->] (q_0) edge node[above,align=center]{$kr$} (q_1) edge node[below,align=center]{$ur$} (q_2);
\path[->] (q_1) edge node[above] {$f$} (q_3);
\path[->] (q_2) edge node[above] {$\varepsilon$} (q_4);
\path[->] (q_4) edge node[above] {$\varepsilon$} (q_5);
\path[->] (q_5) edge node[above] {$f$} (q_6);
\path[->] (q_1) edge [loop above] node[above] {$kr$} ();
\path[->] (q_5) edge [bend left] node[below] {$ur$} (q_2);
\path[->] (q_5) edge node[above] {$kr$} (q_1);
\end{tikzpicture}
\end{document} 

다이어그램의 스크린샷:

여기에 이미지 설명을 입력하세요

답변1

귀하는 align=center중복되며 above left단순히 대신 등을 사용하십시오 above. 라이브러리가 로드 되면 positioning(원하는 경우) 등으로 공간을 균일하게 조정할 수 above left = 2mm and 2mm있습니다 above = 2mm. 하지만 나는 이것을 제안하지 않습니다.

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning}
\usetikzlibrary{automata}
\begin{document}
\begin{tikzpicture}[shorten >=1pt,node distance=2cm,on grid]
\node[state,initial] (q_0) {$q_0$};
\node[state] (q_1) [above right=of q_0] {$q_1$};
\node[state] (q_2) [below right=of q_0] {$q_2$};
\node[state,accepting] (q_3) [right=of q_1] {$q_3$};
\node[state] (q_4) [right=of q_2] {$q_4$};
\node[state] (q_5) [right=of q_4] {$q_5$};
\node[state,accepting] (q_6) [right=of q_5] {$q_6$};
\path[->] (q_0) edge node[above left]{$kr$} (q_1) edge node[below left]{$ur$} (q_2);
\path[->] (q_1) edge node[above] {$f$} (q_3);
\path[->] (q_2) edge node[above] {$\varepsilon$} (q_4);
\path[->] (q_4) edge node[above] {$\varepsilon$} (q_5);
\path[->] (q_5) edge node[above] {$f$} (q_6);
\path[->] (q_1) edge [loop above] node[above] {$kr$} ();
\path[->] (q_5) edge [bend left] node[below] {$ur$} (q_2);
\path[->] (q_5) edge node[above right] {$kr$} (q_1);
\end{tikzpicture}
\end{document}

여기에 이미지 설명을 입력하세요

또 다른 옵션은 다음을 사용하는 것입니다.sloped

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{positioning}
\usetikzlibrary{automata}
\begin{document}
\begin{tikzpicture}[shorten >=1pt,node distance=2cm,on grid]
\node[state,initial] (q_0) {$q_0$};
\node[state] (q_1) [above right=of q_0] {$q_1$};
\node[state] (q_2) [below right=of q_0] {$q_2$};
\node[state,accepting] (q_3) [right=of q_1] {$q_3$};
\node[state] (q_4) [right=of q_2] {$q_4$};
\node[state] (q_5) [right=of q_4] {$q_5$};
\node[state,accepting] (q_6) [right=of q_5] {$q_6$};
\path[->] (q_0) edge node[above,sloped]{$kr$} (q_1) edge node[below,sloped]{$ur$} (q_2);
\path[->] (q_1) edge node[above] {$f$} (q_3);
\path[->] (q_2) edge node[above] {$\varepsilon$} (q_4);
\path[->] (q_4) edge node[above] {$\varepsilon$} (q_5);
\path[->] (q_5) edge node[above] {$f$} (q_6);
\path[->] (q_1) edge [loop above] node[above] {$kr$} ();
\path[->] (q_5) edge [bend left] node[below] {$ur$} (q_2);
\path[->] (q_5) edge node[above,sloped] {$kr$} (q_1);
\end{tikzpicture}
\end{document}

여기에 이미지 설명을 입력하세요

그리고 마지막으로 prettier아시다시피 상대적인 용어입니다.

관련 정보