# How do I make a figure that spans a spread of two pages? [duplicate]

I have a huge TikZ graphic inside a figure environment. I would like it to cover a spread so that the figure is cut in half, and the left half goes on an even (left-hand) page and the right half goes on the next (odd/right-hand) page. I want the regular page margins to apply, and all the rest of the document layout, too. I need to use the IEEE two-column paper format.

I know I could just manually remake the TikZ graphic into two parts and place each part in a new figure environment, and then resort to trickery to force the figures onto the pages I want. But it would be much cleaner and easier to update the graphic if I could make it independently of how it is positioned on the page. Also, if I decide to replace the TikZ graphic with, say, an EPS or PDF (or encounter the same issue another time when I have such an image), I'd like the solution to be independent of what I happen to have inside the figure.

So, how can I make a figure that spans a spread of two pages?

• @PeterGrill: That certainly looks like it could do the trick. I have to try it out. – Fabian Fagerholm Oct 20 '11 at 17:53
• @PeterGrill: After checking out the question you proposed, I'm thinking this is a bit different because in this case, I'm actually generating the graphic with TikZ while the question deals only with spanning pre-generated image files over two pages. – Fabian Fagerholm Oct 20 '11 at 18:13
• Even though it may seem trivial, it is always best to compose a MWE that illustrates the problem including the \documentclass so that those trying to help don't have to recreate it. – Peter Grill Oct 20 '11 at 19:32

You can use the solution I posted for How to include a picture over two pages, left part on left side, right on right (for books)? and then exchange any \includegraphics[<options>]{<image file>} with \adjustbox{<some options>}{<your tikzpicture or similar>} from the adjustbox package instead. It builds on the option keys provided by graphicx and is fully compatible with it, but applies them to text or picture environments instead of graphicx.

What you basically have to do is:

Split the tikzpicture using \clipbox or \adjustbox{clip=...} from the adjustbox package. You need to insert it twice and clip first the left part and then the right part. For this you should store the image first into a box register and then use the register twice. Even better, use my storebox package and the \storebox\mystore{<your image>} and \usestorebox macro which only stores the whole picture once in the PDF, while \savebox / \usebox stores it twice. I actually already wrote a \splitbox macro as part of adjustbox for this kind of thing, but it isn't released yet.

The figure environment makes things a little more tricky. You need to make sure that both are either on top or bottom and do not fall on one figure-only page which will happen if you don't have enough text around it.

Here the code from How to include a picture over two pages, left part on left side, right on right (for books)? modified for picture environments. If you use several of these close to each other you need to use different box registers to hold them.

\documentclass[twoside]{book}

\usepackage{graphicx}
\usepackage{afterpage}
\usepackage{placeins}
\usepackage{xcolor}
\usepackage{tikz}
\usepackage[disable]{storebox}
\newstorebox\twopagestorebox

% For the memoir class remove the following two packages.
% This class already provide the functionality of both
\usepackage{caption}
\usepackage[strict]{changepage}
%%%

\setcounter{totalnumber}{1}
\setcounter{topnumber}{1}
\setcounter{bottomnumber}{1}
\renewcommand{\topfraction}{.99}
\renewcommand{\bottomfraction}{.99}
\renewcommand{\textfraction}{.01}

\makeatletter
\newenvironment{twopagepicture}[3]{%
\def\@dotwopagepicture{\@twopagepicture{#1}{#2}{#3}}%
\begin{storebox}{\twopagestorebox}%
}{%
\end{storebox}%
\ifstorebox
\global\let\twopagestorebox=\twopagestorebox
\else
\global\setbox\twopagestorebox=\box\twopagestorebox
\fi
\@dotwopagepicture{\usestorebox\twopagestorebox}%
}

\newcommand*{\@twopagepicture}[4]{%
\checkoddpage
\ifoddpage
\expandafter\@firstofone
\else
\expandafter\afterpage
\fi
{\afterpage{%
\if #1t%
\if #2p%
\thispagestyle{empty}%
\afterpage{\thispagestyle{empty}}%
\fi
\fi
\begin{figure}[#1]
\if #2p%
\if #1t%
\fi
\fi
\if #1b%
\caption{#3}%
\fi
\makebox[\textwidth][l]{%
\if #2p\relax
\let\mywidth\paperwidth
\hskip-\dimexpr1in+\hoffset+\evensidemargin\relax
\else
\let\mywidth\linewidth
\fi
\if #1b\else
\caption{#3}%
\fi
\if #2p%
\if #1b%
\fi
\fi
\end{figure}%
\begin{figure}[#1]
\if #2p%
\if #1t%
\fi
\fi
\makebox[\textwidth][l]{%
\if #2p%
\let\mywidth\paperwidth
\hskip-\dimexpr1in+\hoffset+\oddsidemargin\relax
\else
\let\mywidth\linewidth
\fi
\if #2p%
\if #1b%
\fi
\fi
\end{figure}%
}}%
}
\makeatother

\usepackage{lipsum}
\begin{document}
\lipsum[1]
\begin{twopagepicture}{b}{l}{Test}
\begin{tikzpicture}
\draw (0,0) -- (2\linewidth,10);
\draw (0,10) -- (2\linewidth,0);
\draw (\linewidth,5) circle (2);
\end{tikzpicture}
\end{twopagepicture}
\lipsum
\lipsum

\end{document}


The result looks like this:

Note that there is a bug in the current version of storebox (v1.0) caused by the update of collectbox. I already fixed it and uploaded v1.1 to CTAN. Please remove the disabled option from it once you have the new version. So far it runs in fallback mode and actually uses saveboxes instead.