TeX - LaTeX Asked by a6623 on May 22, 2021
I have the following automata, and notice that some of the arrows have been eaten by Tikz for some reason. I’ve drawn where I expected to see arrows in red (roughly).
The code is as follows:
begin{tikzpicture}
node[state, initial] (s1) {$s_1$};
node[state, right=2cm of s1] (s2) {$s_2$};
node[state, accepting, right=2cm of s2] (s3) {$s_3$};
draw (s1) edge[loop above] node{0} (s1)
(s1) edge[above] node{1} (s2)
(s2) edge[loop above] node{1} (s2)
(s2) edge[above] node{0} (s3);
end{tikzpicture}
I also imported following libraries:
usetikzlibrary{arrows,automata,positioning}
I based my code off the example on Page 4 here:
https://www3.nd.edu/~kogge/courses/cse30151-fa17/Public/other/tikz_tutorial.pdf
and their output seems to have no eaten arrows.
The tutorial does tikzset{->}
globally. This is why it works in the tutorial. In my opinion this is a somewhat questionable approach.
documentclass{article}
usepackage{tikz}
usetikzlibrary{arrows,automata,positioning}
begin{document}
This is your code fragment:
begin{center}
begin{tikzpicture}
node[state, initial] (s1) {$s_1$};
node[state, right=2cm of s1] (s2) {$s_2$};
node[state, accepting, right=2cm of s2] (s3) {$s_3$};
draw (s1) edge[loop above] node{0} (s1)
(s1) edge[above] node{1} (s2)
(s2) edge[loop above] node{1} (s2)
(s2) edge[above] node{0} (s3);
end{tikzpicture}
end{center}
An appropriate way to get the arrow is to add texttt{->} in a emph{local
group}. (It gets added to the verb|draw| command.)
begin{center}
begin{tikzpicture}
node[state, initial] (s1) {$s_1$};
node[state, right=2cm of s1] (s2) {$s_2$};
node[state, accepting, right=2cm of s2] (s3) {$s_3$};
draw[->] (s1) edge[loop above] node{0} (s1)
(s1) edge[above] node{1} (s2)
(s2) edge[loop above] node{1} (s2)
(s2) edge[above] node{0} (s3);
end{tikzpicture}
end{center}
The tutorial you quote adds verb|tikzset{->}| emph{globally}.
tikzset{->}%
As you saw, this can lead to a lot of confusion, but it also adds the arrows.
begin{center}
begin{tikzpicture}
node[state, initial] (s1) {$s_1$};
node[state, right=2cm of s1] (s2) {$s_2$};
node[state, accepting, right=2cm of s2] (s3) {$s_3$};
draw (s1) edge[loop above] node{0} (s1)
(s1) edge[above] node{1} (s2)
(s2) edge[loop above] node{1} (s2)
(s2) edge[above] node{0} (s3);
end{tikzpicture}
end{center}
If I was you I would avoid adding this globally (and perhaps select another tutorial).
end{document}
Correct answer by user241086 on May 22, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP