Is there a way to insert a diagram generated by Tikz/PGF directly from within a LaTex file? Currently, I am writing it in its own file, compiling it with pdflatex and then including the generated output file as an image.

  • Oops, this appears to be a duplicate question tex.stackexchange.com/questions/28258/…
    – puk
    Commented Feb 8, 2012 at 3:56
  • If you are producing the pictures in a separate file (recommended), then you should also consider using the standalone package. An example is in this question on crop entire document around figure Commented Feb 8, 2012 at 16:22
  • @PeterGrill the standalone package appears to be a more complex version of the input command does it not?
    – puk
    Commented Feb 8, 2012 at 20:25
  • The standalone package can be used to produce complete compilable documents with the tikzpictures, and then you can use \input to imports those directly into the parent document without having to remove/comment the preamble required to compile the tikzpicture by itself. Commented Feb 8, 2012 at 20:48
  • @puk: Have a look at the answer to this question: tex.stackexchange.com/questions/31825/figure-preview-wrapper Commented Feb 9, 2012 at 0:11

2 Answers 2


Yes, this is possible. If you have a file diagram.tex with your TikZ instructions, just use the following

\caption{This is my diagram.}

This should work just fine.

  • I was just about to flag this question as a duplicate, but then you answered. I was not aware that you could input it via an external file. Thanks.
    – puk
    Commented Feb 8, 2012 at 3:55

In the preamble add \usepackage{tikz} and necessary tikz libraries and in the document

    \caption{This is my diagram} \label{fig:diagram}

This enables to control the figure dimensions in your text.

  • can you describe what \resizebox{0.8\textwidth}{!} does
    – puk
    Commented Feb 8, 2012 at 4:38
  • @puk You can adjust the size of the picture. Change 0.8\textwidth to say 0.4\textwidth and see your self.
    – user11232
    Commented Feb 8, 2012 at 7:50

You must log in to answer this question.

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