Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I'm using minipage environments for two images next to each other in a paper. My code looks like this:

    \begin{figure}[htb]
        \centering
            \begin{minipage}{0.5\textwidth}
                \center \includegraphics[width=7.8 cm]{./lorem.jpg}
                \caption{Lorem Ipsum}
            \end{minipage}\hfill
        \centering
            \begin{minipage}{0.5\textwidth}
                \center \includegraphics[width=7.8 cm]{./ipsum.jpg}
                \caption{Ipsum Lorem}
            \end{minipage}      
    \end{figure}

When these images occur at the end of a page, however, and there's not enough room, they are moved to the following page. That's how it's supposed to be, of course; but when this happens, the space after the figure becomes too big. The space has the right size when the figure occurs somewhere in the middle of a page.

By inserting a \clearpage right before the figure manually, I can solve the problem. But as I'd have to do this everytime I change details of the layout, that's not really the best way.

Any suggestions how to solve this problem?

share|improve this question

2 Answers 2

up vote 3 down vote accepted

The space before and after in-text floats is determined by the \intextsep length (in standard classes, by default, 12pt plus 2pt minus 2pt), while the space after top floats and before bottom floats is determined by \textfloatsep (by default, 20pt plus 2pt minus 4pt). To achieve your desired layout, add the following to your preamble:

\setlength{\textfloatsep}{12pt plus 2pt minus 2pt}

See this answer for an overview of float layout parameters.

share|improve this answer
    
Using \textfloatsep and \intextsep definitely was the right idea. I'm still getting varying spaces underneath the figures though. I assume that this is due to the plus / minus, right? –  Daniel Mar 25 '12 at 19:49
1  
@Daniel If you're using the book class and \flushbottom, quite possible. –  lockstep Mar 25 '12 at 22:05

lockstep has provided the answer, this is more of a long comment (but should be useful nonetheless)

You can certainly use

\begin{minipage}{.5\textwidth}
...

but you have to be careful when putting two of them side-by-side, because the minipage environment inserts a little bit of horizontal space immediately after it- this gives an overfull hbox in your code.

You can prevent this by using a % immediately after it

\documentclass{article}
\usepackage[demo]{graphicx}

\begin{document}
    \begin{figure}[htb]
            \begin{minipage}{0.5\textwidth}
                \centering
                \includegraphics[width=.85\textwidth]{./lorem.jpg}
                \caption{Lorem Ipsum}
            \end{minipage}% <-- NOTE this bit!
            \begin{minipage}{0.5\textwidth}
                \centering
                \includegraphics[width=.85\textwidth]{./lorem.jpg}
                \caption{Ipsum Lorem}
            \end{minipage}      
    \end{figure}
\end{document}

Note that you can specify the width of the graphic in terms of the \textwidth of the minipage, which is quite useful as it will scale nicely if you want to change the widths of the minipages later on.

share|improve this answer
    
Certainly interesting, but where is the difference to the \hfill I used before? –  Daniel Mar 25 '12 at 19:39
1  
@Daniel if you use two minipage environments, both of which have width .5\textwidth, then there is no space between them, so \hfill does nothing! Note in particular the % after the first minipage, it's important in this situation to prevent overfull hboxes –  cmhughes Mar 25 '12 at 20:08
    
ah, alright! :) –  Daniel Mar 25 '12 at 20:59

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.