3

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}
6
  • I am interested in this also. I have a latex file with lots of images. Managing images in Latex is always hard for me. We need a book on just the subject of using images with Latex.
    – Nasser
    Feb 12, 2014 at 22:41
  • Perhaps some of the answers at tex.stackexchange.com/questions/2275/… will help you with this (especially the answer from Stefan Kottwitz). I suspect this is the kind of case where for really good results you'll need to do a good deal of manual configuration. At least, so I find whenever I use images. You might even find this easier if you do not insert the images wrapped in figure environments - especially if you want to mix text and images to fill up pages. It would be helpful to have a Minimum Working Example.
    – cfr
    Feb 12, 2014 at 23:56
  • your suggested code has the images scaled to textheight and textwidth with keepaspectratio, so it will always scale to full width (or height) of the page. that gives no flexibility really, if you have two figures and no (or little) intervening text and after scaling full width they are more than .5 of textheight, you will end up with a gap. what do you want to happen, re-order the figures? shrink to half width and put side by side? If you want an automatic solution you need to give a lot more hints to the system, what it may or may not do. Feb 13, 2014 at 1:05
  • @DavidCarlisle How can I give hints and not command to the system? If I set 0.5 I simply have an image half the image but white space still occur...
    – G M
    Feb 13, 2014 at 9:49
  • @cfr I've provided a MWE you can download the image with a dropbox link... Thanks for the hints!
    – G M
    Feb 13, 2014 at 10:29

1 Answer 1

2

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.

2
  • And maybe add a \raggedbottom directive in the preamble?
    – Bernard
    Feb 12, 2014 at 22:43
  • @collegeskier thanks I've tried but I don't see any difference I'm working with an article
    – G M
    Feb 13, 2014 at 10:36

You must log in to answer this question.

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