# Float placement on

I have 16 images (.jpg) I would like to place one to a (photos only) page in the centre of a book. I have tried the following code which places a photo at the end of the current chapter centred on a single page which contains only the photo.

\begin{figure}[p]
\centering
\includegraphics[width=8cm]{jh_one}
\caption{Jim Hitchmough}
\end{figure}


However, is there a way to determine automatically the equidistant centre of the book and to place the 16 pages so that 8 pages fall on either side of the equidistant point (the centre)?

Many thanks, Mike

• By "centre of the book", are you referring to page X, where the book has 2X pages? – Werner Feb 25 '15 at 18:16
• Hi Werner - at this stage I do not know the total number of pages in the book. So, 'page x' would be the page that is 2X/2 - the half way point in the total pages. Perhaps, if a count of pages that are included in the book at any stage would be done to determine 2X/2 - however, each chapter is contained in a separate file (modular project organisation :-)) – Mike Feb 25 '15 at 20:53

To simplify the \testpage macro, I put all the pages to be inserted into insert.tex. It might be a good idea to debug \input{insert} before adding the page hook.

\documentclass{article}
\usepackage{lastpage}
\usepackage{everypage}
\usepackage{afterpage}
\usepackage{lipsum}

\makeatletter
\newcommand{\testpage}{\@ifundefined{lastpage@lastpage}{}%
{\bgroup
\countdef\test=1
\test=\lastpage@lastpage\relax
% subtract number of pages inserted plus 1 or 2
\divide\test by \tw@
\ifnum\test=\value{page}\relax
\smash{\rlap{Inserts will appear in 2 more pages}}% you can remove this
\afterpage{\input{insert}}%
\fi
\egroup}}
\makeatother

\begin{document}
\lipsum[1-30]
\end{document}


Here is the insert.tex file:

\clearpage
\begin{figure}[p]
Insert first photo here
\caption{caption}
\end{figure}
\clearpage
\begin{figure}[p]
Insert second photo here
\caption{ditto}
\end{figure}
\clearpage


On second thought, it would probably be better just to let you specify the page you want the insert to start on. That way you could tweak the location (even or odd page) and I wouldn't have to mess with lastpage.

\documentclass{article}
\usepackage{everypage}
\usepackage{afterpage}
\usepackage{lipsum}

\newcount{\insertpage}
\insertpage=4
% one could use \newcommand{\insertpage}{4} instead

\newcommand{\testpage}%
{\bgroup
\countdef\test=1
\test=\insertpage\relax
\ifnum\test=\value{page}\relax
\afterpage{\input{insert}}%
\fi
\egroup}

\begin{document}
\lipsum[1-30]
\end{document}

• Many thanks John - much appreciated. Will test your suggestion on my files and will let you know. Mike – Mike Feb 26 '15 at 12:47
• John - Thanks!! The code works well - I will now integrate it with the main.tex for the book where there are 36-40 photos to include. Thank you again for the enormous effort, it really is much appreciated. Mike – Mike Feb 26 '15 at 20:24