Use alternate scaling of the image if there is empty space available

I write a book with several chapters. Every chapter contains several (floating) images, usually photos in standard landscape-style, therefore they are scaled to the size of 0.4\textheight so that at least two images fit to the page with the captions (to save space).

I use the following function "\photo" for adding photos:

\newcommand{\photo}[3] {
\begin{figure}[htbp]
\begin{center}
\leavevmode
\includegraphics[height=0.4\textheight]{#2}
\end{center}
\caption{#3}
\label{foto:#1}
\end{figure}
}


However, it often happens that on the very last page of the chapter only one (last) image is shown. As I'm using the scaling, it scales the image to the same 0.4-size, which in this case is not needed, as the remaining part of the page is left empty anyway (end of the chapter), and even scaling up to 0.9\textheight would be possible.

The problem is that I don't know whether the photo is floated to the end of the paragraph or not. Or, is the photo positioned to the last page filled with some text also or with lots of free space available.

The book is actually generated by the program (it is a family tree book, automatically split into chapters), I don't want to edit this manually.

So, is there an option in Latex (LuaLaTex) to

• scale the images to the requested size normally, but
• scale the image up to fill the page in case there is empty space available anyway.

(In short, the scaling should depend on the position where the photo is placed after floating.)

• As long as you use LaTeX's built-in float mechanism, you can't know where exactly LaTeX is going to place your figure. Also, while I don't know what your figures look like, I would think that scaling them up just to fill the space would result in a rather uneven appearance. I would try to keep the proportions, font size etc. consistent between figures. – Michael Palmer Sep 9 '17 at 13:37

I understand that you use \photo command to include images, then you know when there are two or only one image at end of chapter. So I think it's easier to change scaling factor by hand when you need it than writing an automatic way.

In any case, you can introduce a fourth (optional) parameter to your \photo command which is the scale factor (0.4 by default). When you want a full page image, just write \photo[0.9]{label}{image-file}{caption}

\newcommand{\photo}[4][0.4]{
\begin{figure}[htbp]
\begin{center}
\leavevmode
\includegraphics[height=#1\textheight]{#3}
\end{center}
\caption{#4}
\label{foto:#2}
\end{figure}
}

• You are right. But the problem is that I don't know whether the photo is floated to the end of the paragraph or not. In addition, as the book is actually generated by program (it is a family tree book, automatically split into chapters), I don't want to edit this manually later on. – Sulev Reisberg Aug 10 '17 at 11:50
• So, as far as I understand, the scaling should depend on the position where the photo is placed after floating. – Sulev Reisberg Aug 10 '17 at 12:07
• I think all this information is important enough to be mentioned in the question. This way you will avoid answers like mine – Ignasi Aug 10 '17 at 12:36