Mejorando aún más el diagrama de autómatas

Mejorando aún más el diagrama de autómatas

He dibujado un autómata usando la biblioteca tikz.autómatas. Necesito ayuda para perfeccionar el diagrama. No estoy disponible :

  1. Alinee las etiquetas de los bordes (kr, ur, etc.) con el centro, es decir, exactamente entre dos nodos.
  2. Hacer un espacio igual entre las etiquetas del borde y el borde
  3. Haciendo que el diagrama se vea más bonito :) ;)

El código LaTeX es el siguiente:

\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} 

La captura de pantalla del diagrama:

ingrese la descripción de la imagen aquí

Respuesta1

Tu align=centeres redundante y utiliza above leftetc en lugar de simplemente above. Con positioningla biblioteca cargada, puedes ajustar los espacios tú mismo (si lo deseas) mediante above left = 2mm and 2mmy above = 2mmetc para que sean uniformes. Aunque no sugiero esto.

\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}

ingrese la descripción de la imagen aquí

Otra opción es utilizarsloped

\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}

ingrese la descripción de la imagen aquí

Y por fin prettieres un término relativo como ya sabes.

información relacionada