I want to draw a simple graph with the tikz library with the code below:
\begin{tikzpicture}[->,>=stealth',shorten >=1pt,auto,node distance=0.5cm and 3.5cm, auto, semithick]
\tikzset{state/.style={rectangle,rounded corners,draw=black,very thick,inner sep=20pt,sibling distance=25mm}}
\node[state,align=center] (A) {A};
\node[state,align=center] (B) [right =of A] {B};
\path (A) edge [align=center,above] node {$A \rightarrow B$} (B);
\path (B) edge [align=center,below] node {$B \rightarrow A$} (A);
\end{tikzpicture}
My problem is that the edges are overlapping. I read through some comments here and found a solutions but it is not really satisfying (think I am too inexperienced to get it right)
\path ($(A)+(0,0.5)$) edge [align=center,above] node {$A \rightarrow B$} ($(B)+(0,0.5)$);
With this solution is the arrow is calculated from the center of the node and not from its border where it should start. Is it possible to let the arrow start and end at the border of the node?
I also found a second solution:
\path (A)++(0,0.5) edge [align=center,above] node {$A \rightarrow B$} (B)++(0,-0.5);
Here the arrow is also calculated from the center of the node but the second calculation ((B)++(0,-0.5)
) is not applied. Do you have any ideas how I get my described behavior?
Best Answer
your code is very strange:
inspired with nice marmot solution let me show an alternative:
you might wish to combine both solutions at defining coordinates of arrows :-)
edit:
style of edge quotes you can define with
every edge quotes
, for exmple:every edge quotes/.style={align=center,font=\footnotesize, sloped}
with this style (applied to all edge quotes) you write two (or more) lines edge labels aligned to its slope:
edge
for both arrows meanwhile at the first you can notice that for the second arrow is usedto
. this also cause, that now all options in brackets are applied to edge and not only to edge label as before.