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.
2 Answers
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.
-
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.– pukFeb 8, 2012 at 3:55
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\textwidth
to say0.4\textwidth
and see your self.– user11232Feb 8, 2012 at 7:50
standalone
package. An example is in this question on crop entire document around figurestandalone
package appears to be a more complex version of theinput
command does it not?standalone
package can be used to produce complete compilable documents with thetikzpicture
s, and then you can use\input
to imports those directly into the parent document without having to remove/comment the preamble required to compile thetikzpicture
by itself.