1

I'm have a wired situation when I'm fine-tuning the edge position between 2 states with \usetikzlibrary{automata}.

An example:

\begin{tikzpicture}
\tikzstyle{every node}=[font=\tiny]
[
  initial/.style={line width=1pt},
  accepting by double/.append style={line width=1pt},
  semithick,
]
    \draw node (a) [state] at (3, 1) {\footnotesize $a$};
    \draw node (b) [state] at (3, -1) {\footnotesize $b$};
    \path[->] (a) edge [in=120,out=240,looseness=0] node[sloped] {>} (b);
    \path[->] (a) edge [in=100,out=260,looseness=0] node[sloped] {>} (b);
    \path[->] (a) edge [in=80,out=280,looseness=0] node[sloped] {>} (b);
    \path[->] (a) edge [in=60,out=300,looseness=0] node[sloped] {>} (b);
\end{tikzpicture}

This is the output using LaTeXiT, where the texts for 2nd and 4th edge go backwards.

This is the output using LaTeXiT

What more interesting is pdflatex generates a different but still unpredictable texts:

enter image description here

  • 1
    Welcome to TeX.SE! You have a really interesting way of drawing straight lines. I tought to[bend left=0] was original but you clearly beat me. ;-) – user121799 Aug 10 '18 at 19:34
  • Thanks @marmot! I leant it from here! – Laplace_wdd Aug 10 '18 at 20:53
  • Thanks. Tom Bombadil didn't go to zero. It is OK to go to zero, I think, but then there can be side-effects. – user121799 Aug 10 '18 at 20:56
1

To get predictable "texts", refrain from drawing the straight lines in that complicated fashion. If you want to start at a certain angle from a node, you do not have to use out=...,in=..., it suffices to specify the angles in the starting node and target.

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

\begin{tikzpicture}[
  initial/.style={line width=1pt},
  accepting by double/.append style={line width=1pt},
  semithick,
]
\tikzset{every node/.style={font=\tiny}}

    \draw node (a) [state] at (3, 1) {\footnotesize $a$};
    \draw node (b) [state] at (3, -1) {\footnotesize $b$};
    \path[->] (a.240) edge[">",sloped,pos=0.3]  (b.120);
    \path[->] (a.260) edge[">",sloped,pos=0.3]  (b.100);
    \path[->] (a.280) edge[">",sloped,pos=0.3]  (b.80);
    \path[->] (a.300) edge[">",sloped,pos=0.3]  (b.60);
\end{tikzpicture}
\end{document}

enter image description here

And this gives reliable predictable results.

Another way to get the result is to do

\documentclass[border=3.14mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{automata}
\begin{document}

\begin{tikzpicture}[
  initial/.style={line width=1pt},
  accepting by double/.append style={line width=1pt},
  semithick,
]
\tikzset{every node/.style={font=\tiny}}

    \draw node (a) [state] at (3, 1) {\footnotesize $a$};
    \draw node (b) [state] at (3, -1) {\footnotesize $b$};
     \draw[->] (a.240) --  (b.120) node[midway,sloped] {>};
     \draw[->] (a.260) -- (b.100) node[midway,sloped] {>};
     \draw[->] (a.280) -- (b.80) node[midway,sloped] {>};
     \draw[->] (a.300) -- (b.60) node[midway,sloped] {>};
\end{tikzpicture}
\end{document}

which does not rely on quotes. Why is that all happening? TikZ was written by a European, so text flows from left to right. So if the path ends at a larger x coordinate then it started, the text direction is opposite from what it is when the the path ends at a smaller x coordinate then it started. So far, so predictable. What you have found is curious effect when the lines are vertical, in which TikZ must make an ad hoc choice, and, due to the construction of the lines as curves of looseness=0, rounding errors kicked in. These rounding errors are, however, not limited to this situation, it seems.

\documentclass[tikz,border=3.14mm]{standalone}
\usetikzlibrary{automata}
\begin{document}
\tikzset{every node/.style={font=\tiny}}
\foreach \X in {0,5,...,355}
{\pgfmathsetmacro{\Y}{90+2*sin(\X)}
\begin{tikzpicture}[
  initial/.style={line width=1pt},
  accepting by double/.append style={line width=1pt},
  semithick,
]
\path[use as bounding box] (2,-2) rectangle (4,2);
    \draw node (a) [state] at (3, 1) {\footnotesize $a$};
    \node[anchor=west] at (3.2,0) {\Y};
    \node[anchor=east] at (2.8,0) {\X};
    \draw node (b) [state] at (3, -1) {\footnotesize $\X$};
    \draw[->] (a.270) -- (b.\Y) node[midway,sloped] {>};
\end{tikzpicture}}
\end{document}

enter image description here

  • Thanks! It turns out that the looseness=0 is really where the randomness comes from! I got predictable result by setting looseness=.00001 and text goes backwards with looseness=-.00001. I worked out a minimal correction in my question by \path[->] (a.260) edge node[sloped] {>} (b.100);. Thanks for letting me know the angle can be referred in this way! – Laplace_wdd Aug 10 '18 at 21:13
  • @Laplace_wdd Thanks! Yes, that's what I thought. – user121799 Aug 10 '18 at 21:16
  • Hi @marmot, sorry for bothering again. But could you try to add \path[->] (a.250) edge[">",sloped,pos=0.3] (b.130); into your solution and see what's going on? I was modifying my code based on yours but a typo triggered this. – Laplace_wdd Aug 10 '18 at 21:38
  • @Laplace_wdd This works but clearly \path[->] (a.250) edge[">",sloped,pos=0.3] (b.110); looks better. BTW, what are you trying to do with the > signs? If you want to have arrow heads in the middle of the path, there are much better options... – user121799 Aug 10 '18 at 21:40
  • ">" is just showing the correct text directionality for this question. Regarding that extra line of code, I got unpredicted text position as well. Should I update the question to include that? I don't know how to reply with pic (new here) – Laplace_wdd Aug 10 '18 at 21:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.