0

I am writing a book and I want to add several images.

I could add them in between the text but what I want to do (and what I've seen in existing books) is to put images in the middle of the book.

Let's say I have 5 pages of images with their description and my book is 20 pages long with the text, I want to have:

10 (text) / 5 (images) / 10 (text)

I can do it manually by doing page breaks and inserting the images but is it possible to do this dynamically depending on the total number of pages in the document?

6
  • Somewhat related: tex.stackexchange.com/questions/307082/… Sep 28, 2023 at 17:37
  • BTW, the practice of putting pictures together in a multipage signature is due to Smyth Sewing bookbinding. Howver you should use an even number of pages (8 or 16 is typical). Sep 29, 2023 at 13:18
  • Thanks John I'll look at that!
    – johhnry
    Oct 1, 2023 at 17:22
  • If you want more help, we need more deatils. Do you want page numbers and normal margins, or do you want to use pdfpages? Oct 1, 2023 at 22:46
  • Yes I want to use page numbers and normal margins, if I use pdfpages I need to create the pages separatly and include them in the main document which is not ideal
    – johhnry
    Oct 8, 2023 at 19:41

1 Answer 1

1

This uses macros \addpictures and \picturepages to add several pages worth of pictures. In this case I used [p] figures, although that isn't really needed and adds another page delay.

\@abspage@last is a global macro provided by LaTeX (recent addition) in the aux file. It takes two runs to work.

\documentclass{book}
\usepackage{graphicx}
\usepackage{afterpage}
\usepackage{lipsum}% MWE only
\usepackage{duckuments}% MWE only

\newcommand{\picturepages}{5}% number of pages for \addpictures

\newcommand{\addpictures}{\begin{figure}[p]% picture 1
  \includegraphics[width=\textwidth, height=0.5\textheight]{example-image-duck}
  \caption{A cartoon duck.}
\end{figure}
\begin{figure}[p]% picture 2
  \includegraphics[width=\textwidth, height=0.5\textheight]{example-image-duck}
  \caption{A cartoon duck.}
\end{figure}
\begin{figure}[p]% picture 3
  \includegraphics[width=\textwidth, height=0.5\textheight]{example-image-duck}
  \caption{A cartoon duck.}
\end{figure}
\begin{figure}[p]% pictuer 4
  \includegraphics[width=\textwidth, height=0.5\textheight]{example-image-duck}
  \caption{A cartoon duck.}
\end{figure}
\begin{figure}[p]% picure 5
  \includegraphics[width=\textwidth, height=0.5\textheight]{example-image-duck}
  \caption{A cartoon duck.}
\end{figure}}

\newcounter{abspage}% \thepage not reliable
\setcounter{abspage}{1}% adjust for delay

\makeatletter
\AddToHook{shipout/before}{\stepcounter{abspage}%
  \ifnum\@abspage@last=\maxdimen\relax% first run
    \gdef\@abspage@last{0}%
    \afterpage{\addpictures}%
  \else
    \count1=\@abspage@last\relax
    \advance\count1 by -\picturepages\relax%
    \divide\count1 by 2\relax
    \ifnum\count1=\value{abspage}%
      \afterpage{\addpictures}%
    \fi
  \fi}
\makeatother

\begin{document}

\lipsum[1-60]

\end{document}

You must log in to answer this question.

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