Tx · LaTeX & TikZ

How to Export TikZ Figures to EPS

Published By the 9to5Science editorial team

At a glance

  1. 1. Create a standalone figure

    Put the TikZ picture in its own LaTeX file so the output contains only the figure.

  2. 2. Compile to PDF

    Compile the file with pdfLaTeX to produce a vector PDF.

  3. 3. Convert to EPS

    Run Poppler's pdftops with the -eps option on the generated PDF.

  4. 4. Check the result

    Inspect the EPS dimensions, fonts, and appearance in the software that will use it.

TikZ does not generally write an EPS file just because a picture appears in a LaTeX document. You need to compile the picture with a suitable output route or convert its output. A straightforward workflow is to create a standalone PDF of the picture, then convert that PDF to EPS.

Make a standalone TikZ figure

Save the following as figure.tex:

\documentclass[tikz,border=2pt]{standalone}

\begin{document}
\begin{tikzpicture}
  \draw[thick, blue] (0,0) -- (2,0) -- (1,1.5) -- cycle;
  \node at (1,0.45) {Triangle};
\end{tikzpicture}
\end{document}

The standalone class crops the output to the figure, with a small margin set by border=2pt. Its tikz option loads TikZ. If your real figure uses additional packages or libraries, include the required \usepackage and \usetikzlibrary lines in this file too.

Compile the file with pdfLaTeX:

pdflatex figure.tex

This produces figure.pdf. The PDF is usually already suitable for many publishers and workflows. Convert it to EPS only when the destination specifically requires EPS.

Convert the PDF to EPS

Install Poppler’s command-line utilities if pdftops is not already available, then run:

pdftops -eps figure.pdf figure.eps

The -eps option asks pdftops to produce an Encapsulated PostScript file. The result should be a single-page EPS file with a bounding box for the figure. If your system uses a different PDF-to-PostScript utility, check its documentation for an EPS option; the command-line flags are not interchangeable across programs.

This conversion normally retains vector paths as vector output. Any raster images already included in the TikZ figure remain raster images, and features such as transparency may not translate exactly because traditional PostScript does not support PDF transparency in the same way. Inspect the EPS in its intended application before submitting it.

Using TikZ externalization

If your main document uses TikZ’s external library, externalization can compile each picture into a separate file, commonly a PDF. Load the library and enable externalization in the preamble:

\usetikzlibrary{external}
\tikzexternalize

Then compile with shell escape enabled, for example:

pdflatex -shell-escape main.tex

Shell escape allows LaTeX to run external commands, so enable it only for documents and build tools you trust. Externalization is useful when a document has many or expensive TikZ figures, but it does not mean that the externalized output is automatically EPS. Convert the relevant generated PDF using pdftops -eps, just as in the standalone workflow. The generated filenames depend on the document and externalization settings; check the build output or the externalization directory to find the right PDF.

For a single figure, the standalone method is usually easier to understand and reproduce. For a large document, externalization can avoid recompiling unchanged pictures, after which you can convert only the figures that need EPS.

Alternative: compile through DVI and PostScript

A traditional route is to compile with LaTeX to DVI and use dvips to produce PostScript. This can be useful in an existing DVI-based workflow, but the driver and features used by the picture matter. TikZ figures that rely on PDF-specific features may need adjustments, and the PostScript output may be a whole page rather than a tightly cropped EPS. For a predictable cropped figure, PDF followed by pdftops -eps is generally simpler.

Common mistakes

  • Expecting \includegraphics to export TikZ. That command includes graphics; it does not convert a tikzpicture into an EPS file.
  • Using epstopdf in the wrong direction. epstopdf converts EPS to PDF, not PDF to EPS. Use a PDF-to-EPS tool such as pdftops -eps for this workflow.
  • Converting the whole document by accident. If you compile your full paper and convert its PDF, the result is a page of the paper, not a cropped TikZ figure. Compile a standalone figure or externalize the picture first.
  • Assuming the EPS will look identical everywhere. Check fonts, clipping, line weights, and transparency in the target application. Font substitution can occur if the receiving software cannot access the fonts used in the output.
  • Trying to use EPS directly with pdfLaTeX. Standard pdfLaTeX workflows accept PDF, PNG, and JPEG directly, not EPS. Convert EPS to PDF for inclusion, or use a build setup that handles the conversion automatically.

A useful final check is to open the EPS in the application that requested it and confirm that the artwork is cropped correctly and that labels remain legible at the intended size.

References

  1. PGF/TikZ Manual
  2. standalone — Prepare standalone LaTeX documents

Spotted an error? Send a correction. Read how we write and check articles in our editorial policy.