tikz doesn't work properly

I am trying to toy around with tikz and I have found that the result is strange. When I run the code given here:

\documentclass{article}

\usepackage{pgf}
\usepackage{tikz}
\usetikzlibrary{arrows,automata}
\usepackage[latin1]{inputenc}
\begin{document}
\begin{tikzpicture}[->,>=stealth',shorten >=1pt,auto,node distance=2.8cm,
semithick]
\tikzstyle{every state}=[fill=red,draw=none,text=white]

\node[initial,state] (A)                    {$q_a$};
\node[state]         (B) [above right of=A] {$q_b$};
\node[state]         (D) [below right of=A] {$q_d$};
\node[state]         (C) [below right of=B] {$q_c$};
\node[state]         (E) [below of=D]       {$q_e$};

\path (A) edge              node {0,1,L} (B)
edge              node {1,1,R} (C)
(B) edge [loop above] node {1,1,L} (B)
edge              node {0,1,L} (C)
(C) edge              node {0,1,L} (D)
edge [bend left]  node {1,0,R} (E)
(D) edge [loop below] node {1,1,R} (D)
edge              node {0,1,R} (A)
(E) edge [bend left]  node {1,0,R} (A);
\end{tikzpicture}

\end{document}


I get this result: I'm using Ubuntu Natty machine.

• What version of PGF are you using? To find out, you can put \pgfversion immediately after \begin{document} and compile the document again. – Jake May 22 '11 at 13:36
• Works fine for me with PGF v2.10. @Jake: AFAIK Ubuntu Natty still uses TeXLive 2009 :-( – Martin Scharrer May 22 '11 at 13:41
• Version 2.00 and I have found my error. I was running latex and not pdflatex on the document – Yotam May 22 '11 at 14:43
• Wow, that's an interesting result of running LaTeX. You should add this as an answer and accept it, so the question won't be shown as unanswered anymore. Also, you should probably update your TeX distribution (or PGF, at least), PGF 2.00 lacks a number of useful very features (the ability to choose the alignment of text in nodes, for instance). – Jake May 22 '11 at 14:49
• By compiling with latex + dvips + ps2pdf I get the same as when compiling with pdflatex, but latex + dvipdfm(x) doesn't work. – Torbjørn T. May 22 '11 at 15:08

(This answer builds on a number of the earlier comments, I decided to fill in the details since there is no answer currently.) When you compile (reasonably complex) pgf code with latex by default the generated file has all sorts of postscript code in it that dvipdfm(x) can't handle -- lots of errors happen if you look at stderr while converting. This is why dvips -> ps2pdf works, but dvipdfm does not work.

As I understand it pgf will choose what backend driver to use semi-automatically, and if you are running latex it will guess that you want to use dvips. With pdflatex, it will of course automatically use the pdftex driver. If you want to convert a dvi with pgf-generated code using dvipdfm(x), which has no intermediate .ps stage (unlike the similarly named dvipdf), you need to tell it to use the right driver. So, if you want to do latex -> dvipdfm, you need to add the following line before loading pgf/tikz:

\def\pgfsysdriver{pgfsys-dvipdfm.def}


With this line, for me at least, the original code compiles and converts fine with this sequence of commands. The driver system is documented in detail in \S 10.2 of the 2.1 manual. So, in summary, it seems most likely to me that the error is not running latex instead of pdflatex per se, but running latex with a mismatch of the pgf driver and the conversion path.

• To clarify, if you run latex with the pgfsys-dvipdfm backend driver, do you get the right result? – Loop Space May 23 '11 at 6:51
• @Andrew yes, or at least I did. (and I did confirm a very wrong result without doing that, though it is worth noting it didn't look at all like Yotam's wrong result. But what exactly it looks like when it goes wrong is probably very dependent on versions of everything in the chain.) – kgr May 23 '11 at 14:17

I got the same problem, I solved it:

• In Kile's settings -> configure Kile
• go to Tools -> Build
• search for dvitopdf
• change the command to dvipdf instead of dvipdfmx or something, like that.