Das Automatendiagramm noch weiter verbessern

Das Automatendiagramm noch weiter verbessern

Ich habe einen Automaten mit der Tikz-Bibliothek gezeichnetAutomaten. Ich brauche Hilfe bei der Verfeinerung des Diagramms. Ich bin nicht in der Lage:

  1. Richten Sie die Kantenbeschriftungen (kr, ur usw.) auf die Mitte aus, also genau zwischen zwei Knoten
  2. Gleichmäßigen Abstand zwischen den Randbeschriftungen und dem Rand
  3. Damit das Diagramm schöner aussieht :) ;)

Der LaTeX-Code lautet wie folgt:

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

Der Screenshot des Diagramms:

Bildbeschreibung hier eingeben

Antwort1

Ihr align=centerist überflüssig und verwendet above leftetc. statt einfach above. Mit positioninggeladener Bibliothek können Sie die Leerzeichen (wenn Sie möchten) selbst mit above left = 2mm and 2mmund above = 2mmetc. anpassen, sodass sie einheitlich sind. Ich schlage das jedoch nicht vor.

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

Bildbeschreibung hier eingeben

Eine weitere Möglichkeit ist die Verwendungsloped

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

Bildbeschreibung hier eingeben

Und „zuletzt“ prettierist, wie Sie wissen, ein relativer Begriff.

verwandte Informationen