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.
Asked
Active
Viewed 7,562 times
2 Answers
12
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.
Mensch
- 65,388
Timothée Poisot
- 1,385
-
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 08 '12 at 03:55
5
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.
-
-
@puk You can adjust the size of the picture. Change
0.8\textwidthto say0.4\textwidthand see your self. – Feb 08 '12 at 07:50
standalonepackage. An example is in this question on crop entire document around figure – Peter Grill Feb 08 '12 at 16:22standalonepackage appears to be a more complex version of theinputcommand does it not? – puk Feb 08 '12 at 20:25standalonepackage can be used to produce complete compilable documents with thetikzpictures, and then you can use\inputto imports those directly into the parent document without having to remove/comment the preamble required to compile thetikzpictureby itself. – Peter Grill Feb 08 '12 at 20:48