I want to create a TikZ picture in an external PDF file, which then can be included in my main document via \includegraphics
.
However, compiling a document with a TikZ picture in it produces a whole page, meaning lots of white space.
What I want to do can be done using the preview package as described in Standalone diagrams with TikZ?, on SO. But there are some problems with the preview package and XeTex (see Transparency in tikz, preview package and xelatex).
Since creating standalone pictures seems like a natural thing to ask, I am hoping for a different, and maybe more elegant, solution.
Best Answer
You can use the
standalone
class for this. In v0.x it usedpreview
internally, but for v1.x it also has an alternativecrop
option, which works similar to thepreview
option/package, but avoids its issues with XeTeX.There is now (v1.0) also a
tikz
class option which turns any (outer)tikzpicture
into a single tight page. This avoids issues with trailing implicit paragraphs. In addition it automatically loads thetikz
package.Then compile it as usual with
pdflatex
orxelatex
etc.To include this
tikzpicture
into a main document load thestandalone
package there with the optionmode=buildnew
. Then use\includestandalone[<options>]{<filename>}
instead of\includegraphics
. This will compile all includes standalone files automatically as graphics and build these graphics if the source file is newer than the existing graphics file. This needs-shell-escape
to be enabled to allow the main LaTeX run to call further LaTeX compilers. See thestandalone
manual for more details.