0

I'm making a small automata with TiKZ and I need to convert it to a png without having all the empty space around. Right now I get a whole page but I only want the automata.

I have followed the instructions from this link but I couldn't make it work. Compile a LaTeX document into a PNG image that's as short as possible

My original code:

  \documentclass{article}

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

  \begin{document}
  \begin{tikzpicture}[shorten >=1pt,node distance=6cm,on grid,auto]

  \node[state,initial] (q_0)   {$q_0$}; 
  \node[state,accepting](q_3) [right=of q_0] {$q_3$};

  \path[->] 
  (q_0) edge              node {bb+(a+ba)(ab)*(a+bb)} (q_3);

  \end{tikzpicture}
  \end{document}
  • Note that the link uses the standalone class, while you're just using article. Add \pagestyle{empty} to your preamble, followed by a pdfcrop call and use the suggested ImageMagik convert sequence to take the output PDF into PNG. – Werner Jul 17 '14 at 21:22

1 Answers1

1

You can use the standalone class with tikz option.

  \documentclass[tikz]{standalone}

  \usetikzlibrary{automata,positioning}

  \begin{document}
  \begin{tikzpicture}[shorten >=1pt,node distance=6cm,on grid,auto]

  \node[state,initial] (q_0)   {$q_0$}; 
  \node[state,accepting](q_3) [right=of q_0] {$q_3$};

  \path[->] 
  (q_0) edge              node {bb+(a+ba)(ab)*(a+bb)} (q_3);

  \end{tikzpicture}
  \end{document}
SLx64
  • 2,823
  • Thanks. That worked but for some reason L=2 appears at the bottom of the picture. – user59272 Jul 17 '14 at 21:38
  • Have you changed your example? Otherwise, this should not be able to appear. – SLx64 Jul 17 '14 at 21:40
  • No it's the exact same code you gave me. Also the page-nr "1" is there as well. – user59272 Jul 17 '14 at 21:48
  • I think you are doing something wrong. Copy the code from my answer and test it. There shouldn't any page numbers appear. – SLx64 Jul 17 '14 at 21:55
  • I did that but now it doesn't work at all. I use this command in the terminal: convert -density 300 third.pdf -quality 200 3.png – user59272 Jul 17 '14 at 22:00
  • @user59272 Does the PDF appear correctly and the conversion do something odd? Or does your PDF not appear correctly? I suspect you are talking at cross purposes here. There are 2 distinct steps and you need to be clear which one is not working for you. – cfr Jul 18 '14 at 02:12
  • I'm not sure what I did when it worked but the code in my post correctly creates a pdf with the command pdflatex third.tex. Then I want to convert that into a png. When I use user SLx64's code to create a pdf I get the following error-message: `This is pdfTeX, Version 3.1415926-2.5-1.40.14 (TeX Live 2013/Debian) restricted \write18 enabled. entering extended mode (./third.tex LaTeX2e <2011/06/27> Babel <3.9h> and hyphenation patterns for 2 languages loaded.

    ! LaTeX Error: File standalone.cls' not found.

    – user59272 Jul 18 '14 at 07:38
  • @user59272 This error means you don't have standalone class instaled. You don't need it if you follow Werner suggestions: 1.- insert \pagestyle{empty} in your code. 2.- compile with pdflatex. 3.- Use pdfcrop to reduce white space. 4- Convert to png. – Ignasi Jul 18 '14 at 07:53