1

I use the \twopagepicture snippet that's posted here.

How to include a picture over two pages, left part on left side, right on right (for books)?

I need a small adjustment where the figure does not meet the document's edge and is instead shifted away from the edges. It's easy enough to shift the figure vertically, but every time I try to adjust

\let\mywidth\paperwidth 

to

\let\mywidth\paperwidth - <some offset>in

so the horizontal edges go inward, some parts of the figure in the middle are clipped out.

Here is an MWE without me changing it. It tends to align oddly, but it's fine for the main document I'm working on.

\documentclass[10pt,]{article}
\usepackage{graphicx}
\usepackage{adjustbox}
\usepackage{afterpage} 
\usepackage{caption} 

\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%
                % Note #1: Controls vertical positioning of even page.
                % Addition leads to moving the image downward..
                \vspace*{-\dimexpr1in+\voffset+\topmargin+\headheight+\headsep\relax}
            \fi
        \fi
        \if #1b%
            \caption{#4}%
        \fi
        \makebox[\textwidth][l]{%
        \if #2p\relax
            % Controls horizontal positioning of the even page
            \let\mywidth\paperwidth
            \hskip-\dimexpr1in+\hoffset+\evensidemargin\relax
        \else
            \let\mywidth\linewidth
        \fi
        \adjustbox{trim=0 0 {\mywidth} 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} % Note #1.
            \fi
        \fi
        \makebox[\textwidth][l]{%
        \if #2p%
            \let\mywidth\paperwidth
            \hskip-\dimexpr1in+\hoffset+\oddsidemargin\relax
        \else
            \let\mywidth\linewidth
        \fi
        \adjustbox{trim={\mywidth} 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

\begin{document}



The diagonal in the picture should not be broken.

\twopagepicture{t}{p}{diagonal.png}{}

And the picture continues to the next page.

\end{document}

diagonal.png is a simple image. It's not working as intended if there's no space between the top of the page and the figure, and if the line is broken.

Here is what I am trying to go for before someone thinks my question is about removing the file extension. enter image description here

The temporary solution I do, is to make a PNG file with a width that spans the length of two pages, then manually rescale the image (JPG). This almost doubles the file size of the image, so ideally, I'd still like the position handled in LaTeX.

1 Answer 1

1

This question has already been solved by @MartinScharrer --- How to include a picture over two pages, left part on left side, right on right (for books)?

Please note that the source images of your choice need to be inserted as shown below

enter image description here enter image description here

MWE

\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}%<-----insert image source here{image}
\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}
1
  • The problem is that in the question I linked, the figure's edges reach to the page edges. I want to put around 0.5 inches (or variable) amount of space between the figure's edge and the page's edge. I can't adjust it, or I end up clipping middling parts of the image, which isn't good.
    – delu_
    Feb 19, 2020 at 13:10

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .