Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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.

share|improve this question
    
Oops, this appears to be a duplicate question tex.stackexchange.com/questions/28258/… –  puk Feb 8 '12 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 –  Peter Grill Feb 8 '12 at 16:22
    
@PeterGrill the standalone package appears to be a more complex version of the input command does it not? –  puk Feb 8 '12 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. –  Peter Grill Feb 8 '12 at 20:48
    
@puk: Have a look at the answer to this question: tex.stackexchange.com/questions/31825/figure-preview-wrapper –  Hans-Peter E. Kristiansen Feb 9 '12 at 0:11

2 Answers 2

up vote 6 down vote accepted

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

\begin{figure*}[tbp]
\input{diagram.tex}
\caption{This is my diagram.}
\label{f:diagram}
\end{figure*}

This should work just fine.

share|improve this answer
    
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 Feb 8 '12 at 3:55
    
You should put \label always after \caption ... I changed your MWE. –  Kurt Apr 12 '13 at 16:33

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

    \begin{figure}[htb]
    \centering{
    \resizebox{0.8\textwidth}{!}{\input{diagram.tex}}}
    \caption{This is my diagram} \label{fig:diagram}
    \end{figure}

This enables to control the figure dimensions in your text.

share|improve this answer
    
can you describe what \resizebox{0.8\textwidth}{!} does –  puk Feb 8 '12 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. –  Harish Kumar Feb 8 '12 at 7:50

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.