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}
1
  • 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, 2014 at 21:22

1 Answer 1

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}
8
  • Thanks. That worked but for some reason L=2 appears at the bottom of the picture.
    – user59272
    Jul 17, 2014 at 21:38
  • Have you changed your example? Otherwise, this should not be able to appear.
    – SLx64
    Jul 17, 2014 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, 2014 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, 2014 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, 2014 at 22:00

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .