# Page break in the middle of the long figure (image)

I like to include the image in the document which has very large height. Is there any option that lets the tex engine to put a page break in the middle of the image? Note that resizing the image to fit in the page is not an option because that will make my image unreadable.

Note that I don't mind even if the image is splitted in the arbitrary fashion.

• If the image is several times taller than it is wide, and has to span several pages, I think I'd just crop out portions of it for each page. If that process needs to be automated, that should be possible using ImageMagick, IrfanView, or other tools. – Mike Renfro Mar 27 '18 at 4:14

I used the crop option build-in in the regular \includegraphics of standard package graphicx, and automated the process in pure LaTeX, using the packages calc} (for the length) and forloop for the image parts.

Here is a working code (in the multipageimage macro).

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[margin=20mm]{geometry}
\usepackage{graphicx}
\usepackage{calc}
\usepackage{forloop}

\newcommand{\multipageimage}[2][2]{
\newlength{\pageaspectratio}
\setlength{\pageaspectratio}{1pt*\ratio{\textheight}{\textwidth}}
\newlength{\hhimg} \newlength{\wwimg}
\newsavebox{\myimage} \savebox{\myimage}{\includegraphics{#2}}
\settoheight{\hhimg}{\usebox{\myimage}}
\settowidth{\wwimg}{\usebox{\myimage}}
\newcounter{nb} \setcounter{nb}{#1}
\newlength{\newaspectratio}
\setlength{\newaspectratio}{\hhimg*\ratio{1pt}{\wwimg*\real{\thenb}}}
\newlength{\newwidth} \newlength{\newheight}
\ifnum\numexpr\newaspectratio\relax>\numexpr\pageaspectratio\relax
\setlength{\newheight}{\textheight}
\setlength{\newwidth}%
{\wwimg*\real{\thenb}*\ratio{\newheight}{\hhimg}}
\else
\setlength{\newwidth}{\textwidth}
\setlength{\newheight}%
{\hhimg*\ratio{\newwidth}{\wwimg*\real{\thenb}}}
\fi
\newlength{\lowertrim} \newlength{\uppertrim}
\newcounter{img}
\forloop{img}{0}{\value{img} < \value{nb}}{
\setlength{\uppertrim}%
{\hhimg*\ratio{\theimg pt}{\thenb pt}}
\setlength{\lowertrim}%
{\hhimg*\ratio{\thenb pt-\theimg pt-1pt}{\thenb pt}}
\includegraphics[width=\newwidth,height=\newheight,
trim=0 {\the\lowertrim} 0 {\the\uppertrim}, clip=true]{#2}
}
}

\begin{document}

\multipageimage[3]{eiffeltower}

\end{document}


With the result shown below at reduced size and in real size to download (with the image) from mydropbox.

For this example, the number of pages to spread on the image is the first optional parameter (with default to 2) and the image parts are maximized to fit the \textheight or \textwidth according to their aspectratio. This could be easily customized.