# How to extend length of certain arrows in a graph

I'm making a graph using the tikzpictures package. Unfortunately, my graph is a little crowded and forces me to use extra states to keep it clean and ordered. Is there anyway to extend the length of certain arrows.

My code is below. I want to make sure state 5 and 8 can be combined into one state without disrupting the other states.

\begin{tikzpicture}[->,shorten >=1pt,auto,node distance=3cm,
thick,main node/.style={circle,draw,font=\sffamily\large\bfseries}]

\node[main node] (S) {$q_s$};
\node[main node] (1)[above right of=S] {$q_1$};
\node[main node] (2)[above right of=1] {$q_2$};
\node[main node] (3)[above right of=2]{$q_3$};
\node[main node] (4)[below right of=3] {$q_4$};
\node[main node] (5)[below right of=1] {$q_5$};
\node[main node] (6)[above right of=5] {$q_6$};
\node[main node] (7)[below right of=5] {$q_7$};
\node[main node] (8)[below right of=6] {$q_8$};
\node[main node] (9)[below right of=S] {$q_9$};
\node[main node] (10)[below right of=9]{$q_a$};
\node[main node] (11)[below right of=10]{$q_b$};
\node[main node] (12)[above right of=11]{$q_c$};
\node[main node] (13)[above right of=8] {$q_d$};
\node[main node] (14)[below right of=8] {$q_e$};
\node[main node] (15)[right of=13] {$q_f$};
\node[main node] (16)[right of=14]{$q_g$};
%\node[main node] (16)[above right of=15] {$q_g$};
%\node[main node] (17)[below right of=15] {$q_h$};

\path[every node/.style={font=\sffamily\small}]
(S) edge node {1} (1)
edge node[below left] {0} (9)
(1) edge node {0} (5)
edge node {1} (2)
(2) edge node {1} (3)
edge node[left] {0} (6)
(3) edge[loop above] node {1} (3)
edge[bend right] node[left] {0} (6)
(4) edge[loop right] node {0} (4)
edge node[right] {1} (3)
(5) edge node {} (8)
(6) edge [bend right] node[right] {1} (3)
edge node[right] {0} (4)
(7) edge[loop above] node {0} (7)
edge[bend right] node[left] {1} (11)
(8) edge node[left] {1} (14)
edge node [left] {0} (13)
(9) edge node [below left] {0} (10)
edge node[below right] {1} (5)
(10) edge node[below left] {1} (11)
edge node {0} (7)
(11) edge node[below right] {1} (12)
edge[bend right] node[right] {0} (7)
(12) edge [loop right] node {1} (12)
edge node[right] {0} (7)
(13) edge [loop above] node {0} (13)
edge node {1} (15)
(14) edge [loop below] node {1} (14)
edge node[below] {0} (16)
(15) edge node {} (14)
edge[bend right] node {0} (16)
(16) edge node {} (13)
edge[bend right] node {1} (15)
%(16) edge[loop above] node {0} (16)
%(17) edge[loop below] node {1} (17)
\end{tikzpicture}


Welcome! This combines the nodes 5 and 8 to one. More importantly, it uses the positioning library for better positioning (and also quotes).

\documentclass[tikz,border=3mm]{standalone}
\usetikzlibrary{automata,positioning,quotes}
\begin{document}

\begin{tikzpicture}[->,shorten >=1pt,auto,node distance=2cm,
thick,main node/.style={circle,draw,font=\sffamily\large\bfseries}]

\node[main node,initial,initial text={}] (S) {$q_s$};
\node[main node] (1)[above right=of S] {$q_1$};
\node[main node] (2)[above right=of 1] {$q_2$};
\node[main node,double] (3)[above right=of 2]{$q_3$};
\node[main node] (4)[below right=of 3] {$q_4$};
\node[main node] (6)[below right=of 2] {$q_6$};
%  \node[main node] (8)[below right=of 6] {$q_8$};
\node[main node] (9)[below right=of S] {$q_9$};
\node[main node] (10)[below right=of 9]{$q_a$};
\node[main node] (7)[above right=of 10] {$q_7$};
\path (6) -- node[main node,auto=false] (5) {$q_5$} (7);
\node[main node] (11)[below right=of 10]{$q_b$};
\node[main node] (12)[above right=of 11]{$q_c$};
\node[main node] (13)[above right=1cm and 3cm of 5] {$q_d$};
\node[main node] (14)[below right=1cm and 3cm of 5] {$q_e$};
\node[main node] (15)[right=of 13] {$q_f$};
\node[main node] (16)[right=of 14]{$q_g$};
%\node[main node] (16)[above right of=15] {$q_g$};
%\node[main node] (17)[below right of=15] {$q_h$};

\path[every node/.style={font=\sffamily\small}]
(S) edge["1"] (1)
edge node[below left] {0} (9)
(1) edge["0"] (5)
edge["1"] (2)
(2) edge["1"] (3)
edge["0"] (6)
(3) edge[loop above,"1"] (3)
edge[bend right,"0"'] (6)
(4) edge[loop right,"0"] (4)
edge["1"'] (3)
(6) edge [bend right,"1"] (3)
edge["0"'] (4)
(7) edge[loop above,"0"] (7)
edge[bend right,"1"] (11)
(5) edge["1"] (14)
edge["0"] (13)
(9) edge["0"] (10)
edge["1"] (5)
(10) edge["1"] (11)
edge["0"] (7)
(11) edge["1"'] (12)
edge[bend right,"0"] (7)
(12) edge [loop right,"1"] (12)
edge["0"'] (7)
(13) edge [loop above,"0"] (13)
edge["1"] (15)
(14) edge [loop below,"1"] (14)
edge["0"] (16)
(15) edge  (14)
edge[bend right,"0"] (16)
(16) edge  (13)
edge[bend right,"1"] (15)
;
%(16) edge[loop above] node {0} (16)
%(17) edge[loop below] node {1} (17)
\end{tikzpicture}
\end{document}


• Thank you so much! This is exactly what I need! – air bmx Feb 12 at 21:09
• Would you also know how to add a stand alone arrow pointing at state qs without originating from a node? And how to draw a circle within the nodes? – air bmx Feb 12 at 21:17
• @airbmx Sure, both are very easy to obtain with the automata library. If you load it, you can say \node[main node,initial,initial text={}] (S) {$q_s$}; to get the arrow. And if you add double to any of the node's options, it will have a double line (circle in circle). I made the corresponding changes to the answer. – user194703 Feb 13 at 0:10
• I see. Thank you so much! – air bmx Feb 13 at 6:02