129

When writing a long book (from 300 to over a 1000 pages), there is often need to include large pictures and one wishes to have them displayed over two pages, left half on the left page, right half on the right page. If one cuts the picture in two halves and includes them both separately, there is a large possibility that they will not end up each on their respective page (i.e. next to each other).

If there are many many pictures to be added (from 50 to up to 200 pictures per book), splitting each picture in two halves manually is not acceptable, especially if a tiny change in font size shifts the whole document, resulting in a big mess with pictures: the left part now appears on the right page side and vice versa.

Question: How can I create a command

\twopagepicture{position = t or b}{width = l or p}{mypicture.jpg}

with the following properties:

  • t ... top of page
  • b ... bottom of page
  • l ... line width
  • p ... page width

the left half of the picture is displayed on the left page (nearest to the place/text where the command was called) and the right half on the NEXT (right) page.

For example \twopagepicture{t}{l}{mypicture.jpg} is supposed to do this:

enter image description here

And \twopagepicture{t}{p}{mypicture.jpg} is supposed to do this:

enter image description here

By the way, I'm using memoir with a lot of packages:

\documentclass[a4paper,twoside, openodd, final]{memoir}
\usepackage[english]{babel}
\usepackage[top=2.4cm, bottom=2cm, left=2cm, right=2cm]{geometry}
\usepackage{bookman}
\usepackage[pdfpagelayout=TwoPageRight]{hyperref}
\usepackage{longtable}
\usepackage{graphicx}
\usepackage{caption}
\usepackage{verbatim}
\usepackage{color}
\usepackage{tabularx}
\usepackage{multirow}
\usepackage{wrapfig}
\usepackage{fancybox}
\usepackage{framed}
\usepackage{lettrine}
\usepackage{tocloft}
\usepackage{pdfpages}
\usepackage{watermark}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\makechapterstyle{LOTRchapter}{ \renewcommand{\chapterheadstart}{\vspace*{\beforechapskip}\hrule\medskip}           %%
                                \renewcommand{\chapnamefont}{    \fontsize{10mm}{15mm}\selectfont \bfseries}        %%
                                \renewcommand{\chapnumfont}{     \fontsize{10mm}{15mm}\selectfont \bfseries}        %%
                                \renewcommand{\chaptitlefont}{   \fontsize{10mm}{15mm}\selectfont \bfseries}        %%
                                \renewcommand{\printchaptername}{\fontsize{10mm}{15mm}\selectfont \bfseries Chapter}%%
                                \renewcommand{\chapternamenum}{ }                                                   %%
                                \renewcommand{\printchapternum}{\chapnumfont \thechapter}                           %%
                                \renewcommand{\afterchapternum}{. \\}                                               %%
                                \renewcommand{\afterchaptertitle}{\par\nobreak\medskip\hrule\vskip \afterchapskip}  %%
                              }    %definiramo izgled chapterjev (deluje samo v memoir class-u)                     %%
\chapterstyle{LOTRchapter}  %uporabimo pravkar definirani stil chapterjev                                           %%
%%------------------------------------------------------------------------------------------------------------------%%
\setlength{\parindent}{0.75cm}     %zacetni zamik paragrafov                                                        %%
\setlength{\parskip}{0ex}          %vertikalni razmik med paragrafi (stevilo vrstic)                                %%
                                   %\par ... nov paragraf                                                           %%
\def\thechapter{\arabic{chapter}}  %stevilcenje chapterjev z arabskimi stevilkami                                   %%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document}
    \includepdf[pages={-}]{Cover.pdf}
    \leftwatermark{ \put(-56.1,-795){\includegraphics[width=\paperwidth, height=\paperheight]{Background-22.jpg}}}
    \rightwatermark{\put(-56.1,-795){\includegraphics[width=\paperwidth, height=\paperheight]{Background-11.jpg}}} 
lockstep
  • 250,273
Leo
  • 3,499

2 Answers2

133

The following should do it. It needs at least two compiler runs to be stable. With a lot of floats it can take several compilation runs until the document is stable.

Updates:

Works now for twoside mode; now with caption support; Added float settings and removed ! from the float position to also support smaller images; Moved p images to the page corners.

\documentclass[twoside]{book}

\usepackage{graphicx}
\usepackage{adjustbox}
\usepackage{afterpage}
\usepackage{placeins}
\usepackage{xcolor}

% 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
\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%
                \vspace*{-\dimexpr1in+\voffset+\topmargin+\headheight+\headsep\relax}%
            \fi
        \fi
        \if #1b%
            \caption{#4}%
        \fi
        \makebox[\textwidth][l]{%
        \if #2p\relax
            \let\mywidth\paperwidth
            \hskip-\dimexpr1in+\hoffset+\evensidemargin\relax
        \else
            \let\mywidth\linewidth
        \fi
        \adjustbox{trim=0 0 {.5\width} 0,clip}{\includegraphics[width=2\mywidth]{#3}}}%
        \if #1b\else
            \caption{#4}%
        \fi
        \if #2p%
            \if #1b%
                \vspace*{-\dimexpr\paperheight-\textheight-1in-\voffset-\topmargin-\headheight-\headsep\relax}%
            \fi
        \fi
    \end{figure}%
    \begin{figure}[#1]
        \if #2p%
            \if #1t%
                \vspace*{-\dimexpr1in+\voffset+\topmargin+\headheight+\headsep\relax}%
            \fi
        \fi
        \makebox[\textwidth][l]{%
        \if #2p%
            \let\mywidth\paperwidth
            \hskip-\dimexpr1in+\hoffset+\oddsidemargin\relax
        \else
            \let\mywidth\linewidth
        \fi
        \adjustbox{trim={.5\width} 0 0 0,clip}{\includegraphics[width=2\mywidth]{#3}}}%
        \if #2p%
            \if #1b%
                \vspace*{-\dimexpr\paperheight-\textheight-1in-\voffset-\topmargin-\headheight-\headsep\relax}%
            \fi
        \fi
    \end{figure}%
    }}%
}
\makeatother

\usepackage{lipsum}
\begin{document}
\lipsum
\lipsum
\twopagepicture{b}{l}{image}{Test}
\lipsum
\twopagepicture{t}{l}{image}{Test}
\lipsum
\twopagepicture{b}{p}{image}{Other test}
\lipsum
\twopagepicture{t}{p}{image}{Other test with 
very very very very very very very very very very very
very very very very very very very very very very very
very very very very very very very very very very very
long caption
}
\lipsum
\lipsum

\end{document}

Result

(The image shown is a panorama photo made by me from top of the Preikestolen mountain, Norway)

Martin Scharrer
  • 262,582
  • @Leon: Do you want the same caption on both sides? I think it should only be displayed on the first page. – Martin Scharrer Jul 22 '11 at 23:40
  • @Leon: I added it now with the caption only at the first side. For bottom figures the caption is added a second time but as white text to ensure the correct alignment. – Martin Scharrer Jul 22 '11 at 23:51
  • LaTeX Error: File 'adjustbox.sty' not found. Does this mean I don't yet have that package installed? Where can I find that package? Can't see any .stys here http://www.ctan.org/tex-archive/macros/latex/contrib/adjustbox. I assume I just put the file adjustbox.sty in the right folder? – Leo Jul 22 '11 at 23:55
  • @Leon: get both the .ins and .dtx file and compile the .ins file with LaTeX. If you have a big problem installing it I could reprogram the code to work without it. – Martin Scharrer Jul 23 '11 at 00:11
  • I was finally able to create the .sty and process the page. Sorry I'm so clumy with TeX. My only request: could the \twopagepicture{t}{p}{mypicture.jpg} command display the picture at the very top of the page (just like in my second example, it's 0pt from the top page border), and the same with \twopagepicture{b}{p}{mypicture.jpg} and bottom of page. – Leo Jul 23 '11 at 00:45
  • @Leon: here you go. – Martin Scharrer Jul 23 '11 at 01:15
  • 1
    You are a little box of magic :). Thank you so much, this means a lot to me. Your code now seems to be working very nice. The only problem remaining is that when I use the code in my actual book file, I get a Option clash for package changepage, but do not concern yourself with that. I'll try to fix the problem with my friend who knows a bit more TeX than me. I would only like to ask you to check this page in the following two days, in case we're still stuck with the problem and asking for help. Again, thank you very very very much :). – Leo Jul 23 '11 at 01:38
  • 8
    @Leon: For memoir simply remove the changepage and the caption package, then it should work fine! – Martin Scharrer Jul 23 '11 at 01:40
  • Excellent, now it works perfectly. Thank you so much, I feel like I owe you a lot. I hope if I encounter any problems with this command, that you'd be willing to still help. – Leo Jul 23 '11 at 01:53
  • 22
    Very nice. This might deserve a new package :-) – raphink Sep 14 '11 at 08:09
  • Amazing solution, however it does not work properly for me sometimes - it can put the first image on the right page. Is there a workaround? – Dmitry Sep 14 '11 at 01:11
  • @Hippopotamus: Make sure that you compile the document at least twice after any change which affects the location of the images. Otherwise they might be placed incorrectly after the first compiler run. – Martin Scharrer Sep 14 '11 at 09:36
  • 15
    I second the idea of turning this into a new package. There is, however, one additional option I would like to see (and you had asked about in your first comment): The possibility to typeset long captions over both sides. IMHO this gives a smoother layout; furthermore I have several large facing-pages figures with long captions that otherwise do not fit on the pages. (I have achieved this more or less manually so far) – Daniel Sep 14 '11 at 09:39
  • @Daniel: Automatically splitting a long caption over two pages would be a little difficult, but AFAIK it might be technically possible. – Martin Scharrer Sep 14 '11 at 09:41
  • @MartinScharrer How to include a white caption on the LHS portion of the image? – Myriam Iskander May 27 '12 at 09:04
  • @MartinScharrer, This amazing fix breakes with the underscore package. – SpmP May 05 '14 at 05:22
  • 1
    @Daniel: I third that. – Moss_the_TeXie Sep 02 '17 at 16:45
  • @MartinScharrer: Very impressive! There might still be a few more set screws to be added, though, such as the horizontal positions of the picture limits. One might have a picture run from text column to text column but without the central gap, or one might add a binding correction or some cropping margin, or even have the picture run a little smaller or broader than the text columns … you get the picture, I think. – Moss_the_TeXie Sep 02 '17 at 16:45
  • This is very useful! But infotunatly, it didn't work properly on a two colum document :( – Krozark Jun 28 '18 at 15:32
  • Note that this does not work if your image is square – user2589273 Feb 14 '20 at 20:21
  • Has anyone been able to adapt this to work with the tufte class? – brunobg Oct 21 '20 at 01:53
  • The full spread image is what I need and thanks! BUT: Im not able to force the image to start at a specific page. For example: I want to start a chapter on page 1, and I want the spread on page 2 and 3, then the text to continues on page 4. Can't find a way to force this! THANKS! – Haim May 27 '22 at 01:28
9

As of mid-2021, a new version of the package hvfloat, by Herbert Voß, has been available on CTAN.

In addition to the ability to split wide pictures onto two facing pages, this package can rotate images and captions, and handle both single- and two-column pages with ordinary floats and the * forms.

A well-illustrated article appears in TUGboat 42:3; until the first issue of volume 43 appears in spring of 2022, this is accessible only to TUG members.