4

I'm trying to embed TiKZ code in my LyX document. When exporting the document to pdf (pdflatex) I get a blank area instead of the TiKZ output. Here's what I've done:

I've added the following two lines to LaTeX Preamble:

\usepackage{tikz}
\usetikzlibrary{automata,positioning}

I've added the following to a new TeX code:

\begin{tikzpicture}[shorten >=1pt, node distance=2cm, on grid, auto]
    \node[state, initial] (q_0) {$q_0$};
    \node[state] (q_1) [above right=of q_0] {$q_1$};
    \node[state] (q_2) [below right=of q_0] {$q_2$};
    \node[state, accepting] (q_3) [below right=of q_1] {$q_3$};
    \path[->]
    (q_0) edge node {0} (q_1)
          edge node [swap] {1} (q_2)
    (q_1) edge node {1} (q_3)
          edge [loop above] node {0} ()
    (q_2) edge node [swap] {0} (q_3)
          edge [loop below] node {1} ();
\end{tikzpicture}

(The code is copied from another tex.stackexchange answer: Which package can be used to draw automata?)

What's wrong with what I've done?

snakile
  • 141
  • Did you get any error messages? Note also that the TikZ codes should be copied into the ERT box of LyX. – Herr K. Oct 20 '13 at 18:37
  • 1
    On LyX 2.0.6 using MikTeX, using a copy-pasted code inside the ERT gave me no errors, and the appropriate image – TheVal Oct 20 '13 at 18:58
  • @KevinC: I didn't get any error message and the TikZ code is indeed inside an ERT box. – snakile Oct 20 '13 at 19:05
  • @AndreaL.: Could you please share the actual LyX file from which you have generated the pdf? – snakile Oct 20 '13 at 19:06
  • 4
    @snakile Yeah, no problem. Here is the main *.lyx file: This is the first document – TheVal Oct 20 '13 at 19:12
  • Also note that there are some TikZ examples if you go to File > Open, click on the "examples" button, and go to instant_preview.lyx – scottkosty Oct 20 '13 at 20:12
  • The code snippet works fine in an ERT here as well, does it still not work at your end? If that is the case, can you create a minimal example and edit your question to include the contents of the .lyx file (it is a plain text file, so just open it in a text editor and copy the text) or at least the exported LaTeX source code. – Torbjørn T. Nov 06 '13 at 22:13

1 Answers1

1

I've used this preamble and it works with lyx 2.0.6 and miktex. I suppose you must add the arrows tikzlibrary:

\usepackage{tikz, pgf, pgfplots}
\usetikzlibrary{automata,positioning}
\usetikzlibrary{arrows,backgrounds,plotmarks}
\pgfplotsset{width=7cm,compat=newest}
\pgfplotsset{plot coordinates/math parser=false}
Tobal
  • 805
  • 8
  • 16
  • arrows isn't necessary for the code in the question. (And neither is pgfplots, backgrounds and plotmarks, for that matter.) – Torbjørn T. Nov 02 '13 at 12:37