[Tex/LaTex] Is possible to make LaTeX automatically choose the image size to minimize white space

floatsgraphics

I'm working with a lot of images and not much text. When I compile the LaTeX document usually I have an image in every page and a lot of white space between them. These are pages from my LaTeX document.

enter image description here

I would like to have more images in a single page and text between an image and the other so ultimately I would like to have no white space in my document. So far I've try different approaches.
Put figures together in a single page:

\begin{figure}
\includegraphics[width=\textwidth, height=\textheight, keepaspectratio]{figureB}
\includegraphics[width=\textwidth, height=\textheight, keepaspectratio]{figureA}
\end{figure}

Use wrapfigure:

\begin{wrapfigure}{r}{\textwidth}
\includegraphics[width=\textwidth]{figureA}
\end{wrapfigure}

Using [H]with floatpackage. But at the end all this attempts require me to struggle with the figure dimension to fit them otherwise white areas reappear. Are there any way to make TeX automatically choose the dimension of the image for minimizing the white space and maximizing the image dimension? Or alternatively: How can I minimize the white space in other ways?

This is a MWE with the first solution, however I don't know if is better to make a single figure with figure B and C or with A and B or C and D you can download the sample images here:

\documentclass[12pt,a4paper]{article}
\usepackage{graphicx}
\usepackage[utf8]{inputenc}
\usepackage{lipsum}
\usepackage[left=2cm,right=2cm,top=2cm,bottom=2cm]{geometry}
\author{G M}
\title{Is possible to make LaTeX automatically choose the image size to minimize white space?} 
\begin{document}
\maketitle
\lipsum[1-2]
\begin{figure}
\includegraphics[width=\textwidth, height=\textheight, keepaspectratio]{FigureA.jpg} 
\end{figure}

\begin{figure}
\includegraphics[width=\textwidth, height=\textheight, keepaspectratio]{FigureB.jpg} 
\caption{This image and caption is okay but the next image-caption go out of the page, this is because this caption is to long and the image width is fixed to textwidth I know if I don't write this in this caption this don't happen, I've write this caption so long to show you what happen to me many times \ldots}
\includegraphics[width=\textwidth, height=\textheight, keepaspectratio]{FigureC.jpg} 
\caption{Oh no this caption can't be see goes out of the page \ldots How can I fix it?}
\end{figure}
\lipsum[3-5]
\begin{figure}
\includegraphics[width=\textwidth, height=\textheight, keepaspectratio]{FigureD.jpg} 
\end{figure}

\end{document}

Best Answer

I believe your problem might come from LaTeX wanting to have a decent amount of text on each page. You can change this with \renewcommand{\textfraction}{.1}. There is also a \floatpagefraction command. Although I have generally used this to force all images to the end. Lowering the number will allow LaTeX to better fill the white space with text as opposed to image only pages. Additionally you might want to scale figures such that 2 figures fit per page better, but that will have more left right white space.

Related Question