I am trying to draw a Markov chain using tikz
. The diagram is in the correct setup except the arrow going from State 2 and 3 overlaps two other arrows. I tried repositioning the states using node distance
but that did not seem to work. How can I force the arrows not to overlap?
%latex
\documentclass[reqno]{amsart}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{hyperref}
\usepackage{pgfplots}
\usepgfplotslibrary{fillbetween}
\usepackage{tikz}
\usetikzlibrary{automata}
\usetikzlibrary{positioning} % ...positioning nodes
\usetikzlibrary{arrows} % ...customizing arrows
\tikzset{node distance=4.5cm, % Minimum distance between two nodes. Change if necessary.
every state/.style={ % Sets the properties for each state
semithick,
fill=gray!10},
initial text={}, % No label on start arrow
double distance=4pt, % Adjust appearance of accept states
every edge/.style={ % Sets the properties for each transition
draw,
->,>=stealth', % Makes edges directed with bold arrowheads
auto,
semithick}}
\begin{document}
\begin{figure}[htb]
\centering
\begin{tikzpicture}
\node[state] (s1) {State 1};
\node[state, below right of=s1] (s2) {State 2};
\node[state, below left of=s1] (s3) {State 3};
\draw (s1) edge[loop above] node {} (s1);
\draw (s1) edge[bend left] node {} (s2);
\draw (s1) edge[bend right] node {} (s3);
\draw (s2) edge[bend left] node {} (s1);
\draw (s2) edge[loop right] node {} (s2);
\draw (s2) edge[bend right] node {} (s3);
\draw (s3) edge[bend right] node {} (s1);
\draw (s3) edge[bend right] node {} (s2);
\draw (s3) edge[loop left] node {} (s3);
\end{tikzpicture}
\end{figure}
\end{document}
Best Answer
bend left
andbend right
come with parameters, the bending angles. Adjusting them allows you to avoid the intersections. (BTW, I also removed packages that were not used. Note also that thearrows
library got superseded byarrows.meta
but I keptarrows
for now.)