I am fairly new to LaTeX and especially to tikz. I tried to draw a directed graph which actually turned out the way I wanted it to. I don't know how well written this code is, but it works. Code in question:
\begin{tikzpicture}[>=Stealth,->,line width=1pt, domain=0:2,label/.style={%
postaction={ decorate,transform shape,
decoration={ markings, mark=at position 0.5 with \node #1;}}}]
\matrix [matrix of math nodes,
column sep={1.5cm,between origins},
row sep={2.2cm,between origins},
nodes={circle, draw, minimum size=1cm}] {
& |(1)| J & & |(2)| A & \\
& & |(3)| R & \\};
\draw[label={[below]{$50$}}] (2)--(1);
\draw[label={[below]{$25 \%$}}] (3)--(2);
\draw[transform canvas={xshift=2pt, yshift=2pt}, shorten <= -1pt, label= {[below]{$100$}}] (3)--(1);
\draw[transform canvas={xshift=-2pt, yshift=-2pt}, shorten <= -1pt, label= {[below]{$2 \%$}}] (1)--(3);
\end{tikzpicture}
However, after discovering a working solution to add labels to the lines drawn, I now have the problems that the topmost label is upside down. Why this is so, is clear to me, however I don't know how to fix it.
I have read something about doing stuff like
\draw[label={[below, rotate=180]{$50$}}] (2)--(1);
but it's not working.
If you happen to know how to solve my problem or improve the structure of the directed graph, I would be very grateful!
Best Answer
Your picture remind me on automaton, so why don't use
automata
library?It gives:
Since
sloped
option of edge nodes doesn't put edge labels on the middle of the pat, I manually correct their position (by trial).Upgrade: by use of library
quotes
the draw this automation is even simpler:Obtained picture is almost the same (this time in "black and white" version). And here is not necessary manual adjusting of edge labels ...
Edit: I was not aware with possible implication of used babel on the provided code. One solution, how to copy with this provide OP:
Another, more general -- as remind me Gonzalo Medina -- is use babel library:
I correct both above examples accordingly.