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.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm helping TeX a professor's handwritten notes for publishing/pre-print purposes, and for producing certain graphics, I use PGF/TikZ. However, it seems he is having trouble compiling the code whenever TikZ is involved, so he wants me to compile the TikZ images separately, and then \includegraphics on all of them instead. (Seems a bit of a crime, but boss' orders I guess.)

However, trying to make the TikZ images standalone (i.e. including the TikZ code, some article document class, then compiling to .pdf), I am left with a huge amount of whitespace coming from the rest of the single page document. This leads to a lot of problems trying to \includegraphics with it, as the image itself is miniscule compared to all the blank space.

Is there a way to shorten the produced pages to fit exactly the dimensions of the TikZ-images? Or aside from dropping TikZ and going with a third party software, is there perhaps a better solution overall?

share|improve this question
Use \documentclass{standalone} in your figures document. Also be sure to include the same packages than your professor, in order to guarantee that the same typefaces, font sizes, mathematical notation, etc. are used. Also try to create the figures in their final size, so that \includegraphics won't require any scale, width or height option. This way the size of the fonts and line widths will be consistent among all figures. – JLDiaz Mar 10 '13 at 21:33
you could also look into the external library which also has an extra library to include the created PDF's without using TikZ. See the section Using External Graphics Without pgf Installed in the manual. – zeroth Mar 10 '13 at 21:46
Both of these are fantastic answers, though I'm going with zeroth's. :) I tried using the standalone document class in and of itself, but it still required some fussing with the scaling to get it to work as if I inputted the TikZ code normally. On the other hand, the external library as described by zeroth is an excellent way to export all my TikZ code to separate .pdfs without having to manually compile separate .tex documents. And it didn't run into the above problem I had with the standalone document class either (which is kind of weird to be honest, but whatever). – Dustin Tran Mar 11 '13 at 0:51
@zeroth Thanks. – percusse Mar 23 '13 at 0:19
up vote 3 down vote accepted

As mentioned you can use a package which mimics the internals of a tikzpicture but requiring that the images created by the external library are included.

This is very well explained in the manual of pgf, but I will explain how to use it.

First of, your regular local document will be having regular tikzset commands etc.



Text ... 

  \draw [->] (0,0) -- (2,3);


This will create the document with the externalized picture creating a picture named arrow.pdf.

Now lets imagine you are done and wish to collaborate with a non-TikZian. This will probably also mean that he does not have any pgf/tikz packages installed.

  1. First thing is to find the file tikzexternal.sty, it should be located in your TeX-tree under:

  2. Copy this file to your main-TeX file folder.

  3. Comment out your \usepackage{tikz,pgf,pgfplots}.

  4. Comment out any \usetikzlibrary, \usepgfplotslibrary, etc.

  5. Add the usage of the package \usepackage{tikzexternal}.

  6. You do not need to comment out any \tikzset commands as that will be emulated away

The above things which should be commented out, can be performed by local \iffalse ... \fi statements, but the explicit comment out is more rigorous when distributing it to others.

This should give you a document like so:


Text ... 

  \draw [->] (0,0) -- (2,3);


And compile to find that TikZ is not used, but loading of the image is correct.

However, there are some caveats in using this method. First off, the entire key-value system in keys are not present. Hence, all references to external settings should be performed using the designated commands:

  1. Use \tikzsetexternalprefix instead of the key prefix
  2. Use \tikzsetfigurename instead of the key figure name
  3. Not even the content in \tikzexternalize[<content>] will be recognized.

Also, the package tikzexternal gobbles the tikzpicture environment, hence the full environment should be visible (don't do any fancy things here :) ).

share|improve this answer

Your Answer


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.