# Tikz externalization figure not aligned/caption missing

I am putting a presentation together using beamer. I have a few tikz/pgf pictures that I externalize. Yet the figures are not put back into the document correctly. They are not in the right spot on the slides and the captions are missing. The externalization did produce the figures correctly as far as I can tell. I have the same problem when using the hyperref package in article class documents. As far as I know beamer uses hyperref in itself?

I am unsure how to circumvent this issue, any ideas?

Here's a simple working example

\documentclass[red]{beamer}
\usepackage{tikz}
\usepackage{pgfplots}
\usepgfplotslibrary{external}
\tikzexternalize
\tikzset{external/system call={latex \tikzexternalcheckshellescape -halt-on-error -interaction=batchmode -jobname "\image" "\texsource"; dvips -o "\image".ps "\image".dvi}}
\tikzset{external/force remake}
\begin{document}
\frame{
\begin{figure}
\centering
\tikzsetnextfilename{MyFig}
\begin{tikzpicture}
\begin{axis}[xmin=0,xmax=5,
ymin=1,ymax=6,
domain=0:5]
\end{axis}
\end{tikzpicture}
\label{fig:MyFig}
\caption{This text is missing}
\end{figure}
}
\end{document}


I compile with, with TeXLive:

latex -interaction=nonstopmode -shell-escape %.tex; dvips -o %.ps %.dvi; ps2pdf %.ps

-
It works fine for me. Can you post your compile logs? BTW, you should use \begin{frame}...\end{frame} instead of \frame{...} –  Aaron Jun 12 '12 at 4:10
Any recommendations where to upload them to? Both the main log and the externalized log are 1000+ lines. Doesn't seem suitable to copy paste them on here... :) –  Markus Jun 12 '12 at 15:53
Here the main log and externalized log –  Markus Jun 12 '12 at 16:05
This seems to be a driver issue: the generated MyFig.ps has a wrong bounding box. In fact, MyFig.dvi contains two bounding box instructions: the first is wrong, the second is correct... might be something between beamer and tikzexternal. –  Christian Feuersänger Jun 18 '12 at 20:10

This is a driver incompatibility between geometry and tikz: geometry issues some \special paper size options before tikz can.

A work-around seems to be to add

\tikzifexternalizing{%
\geometry{driver=none}
}{}%


This tells geometry to avoid changing the paper size - but only if an external image is currently being generated.

An alternative is to use a different driver (pdflatex does not seem to be affected).

-
I have added support for this detection to PGF CVS, i.e. it will become part of the next version of PGF. –  Christian Feuersänger Jun 18 '12 at 20:40

A workaround I have found, is to go the pdf2ps route within the externalization. I am quite lost as to why this works...

\documentclass[red]{beamer}
\usepackage{tikz}
\usepackage{pgfplots}
\usepgfplotslibrary{external}
\tikzexternalize
%%\tikzset{external/system call={latex \tikzexternalcheckshellescape -halt-on-error -interaction=batchmode -jobname "\image" "\texsource"; dvips -o "\image".ps "\image".dvi}}
\tikzset{external/system call={pdflatex \tikzexternalcheckshellescape -halt-on-error -interaction=batchmode -jobname "\image" "\texsource"; pdf2ps "\image".pdf "\image".ps}}
\tikzset{external/force remake}
\begin{document}
\frame{
\begin{figure}
\centering
\tikzsetnextfilename{MyFig}
\begin{tikzpicture}
\begin{axis}[xmin=0,xmax=5,
ymin=1,ymax=6,
domain=0:5]

even better: use pdftops -level3 -eps -paper match "\image".pdf "\image".eps instead of pdf2ps to greatly reduce file size. –  Markus Jun 18 '12 at 18:54