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 have some figure, which I want to have one right after another in the document. Is it possible to forbid pasting anything inbetween, even if there is some space?

\begin{figure}[h!bt]
\includegraphics[scale=1]{images/shape.png}
\caption{ShapeWithSlotsDoubleLevel}
\label{fig:ShapeWithSlotsDoubleLevel}
\end{figure}

\begin{figure}[h!bt]
\includegraphics[scale=1]{images/shape2.png}
\caption{ShapeWithSlotsDoubleLevel}
\label{fig:ShapeWithSlotsDoubleLevel}
\end{figure}
share|improve this question
1  
Related: tex.stackexchange.com/questions/3457/… –  Jukka Suomela Dec 21 '11 at 20:43

2 Answers 2

up vote 4 down vote accepted

I assume that you want to create two individual floats rather than one float that combines two distinct images, in part so that you can (i) assign separate captions and labels to the two figures, (ii) preserve the capability of creating separate cross-references to them, and (iii) preserve compatibility with the hyperref package. If, however, you're OK with placing two images within a single LaTeX float (which also ensures, of course, that they'll never be separated), you should follow the suggestions provided in the answer of @cmhughes instead.

Meeting the objective expressed in the preceding sentence and ensuring that the two floats will be placed consecutively (i.e., without any text between them) is, I believe, not possible in general if there are no constraints whatsoever on the size of the figures. To wit, if each figure's height is greater than 0.5\textheight, then there's no way LaTeX can place them on the same page...

For the sake of this discussion, I'll therefore assume that the figures' combined height does not exceed the LaTeX parameter \floatpagefraction. The default value of this parameter in the article document class is only 0.5, meaning that if the height of a float (or of a combination of floats) exceeds 0.5, the float(s) will be placed on a separate page. Aside: I would recommend that you issue the commands

\renewcommand\topfraction{0.85}
\renewcommand\bottomfraction{0.85}
\renewcommand\textfraction{0.1}
\renewcommand\floatpagefraction{0.85}

in your document's preamble. This way, LaTeX will permit some text to coexist with floats as long as the floats' combined height doesn't exceed 85% of \textheight.

After this lengthy introduction, what can be done to answer your question? I will go ahead and make the further assumption that the two floats that should be placed together, without intervening text, should be placed at the top of the page. The following code, which uses the \afterpage command of the afterpage package, will do the trick for you:

\afterpage{%
\clearpage\clearpage 
  % Begin by clearing out all accumulated floats (if any) and relaxing some
  % of LaTeX's restrictions on how floats may be placed
\begin{figure}[t]
\caption{This is the first of two consecutive figures}\label{fig:firstoftwo}
...
\end{figure}

\begin{figure}[h]
\caption{This is the second of two consecutive figures}\label{fig:secondoftwo}
...
\end{figure}
}    % end of \afterpage{...} group

By assumption, the two figures fit on a single page and, moreover, their combined height is less than \floatpagefraction. (You have already increased the values of \topfraction and \floatpagefraction, haven't you?) The first \clearpage instruction clears out any already-pending floats, while the second \clearpage command ensures that we are indeed going to start at the top of the page. (If there are no pending floats, both the first and second \clearpage instructions are ignored because we're already at the top of the page.) Observe the t and h placement parameters on the two floats: they will be applied successfully in the present case, with no intervening text, because you're guaranteed to be at the top of a page (because of the \afterpage statement and the \clearpage commands).

By the way, you can change the distance between the two adjoining floats by changing the value of the length parameter \floatsep (default value in the article document class is the main text's font size is 10pt: "12pt plus 2pt minus 2pt"). If you want to increase the vertical separation between the floats, you could select, say,

\setlength\floatsep{1.5\baselineskip plus 0.25\baselineskip minus 0.25\baselineskip}

It's a good idea to keep this length a "rubber" length, by the way, as the presence of rubber lengths greatly facilitates LaTeX's job of finding decent page breaks.

share|improve this answer

If you want them right after each other, you could put them in the same float:

\begin{figure}[h!bt]
    \centering
    \includegraphics[scale=1]{images/shape.png}
    \caption{ShapeWithSlotsDoubleLevel}
    \label{fig:firstlabel}
    \includegraphics[scale=1]{images/shape2.png}
    \caption{ShapeWithSlotsDoubleLevel}
    \label{fig:secondlabel}
\end{figure}

Of course, this wouldn't allow a pagebreak between them. On @Wernser's suggestion, you could also put \par\vspace{\intextsep} after the first label.

Another option would be to put them side by side using minipages; note the % after \end{minipage} to avoid extra (unwanted) space.

\begin{figure}[h!bt]
  \begin{minipage}{0.5\textwidth}
     \centering
     \includegraphics[scale=1]{images/shape.png}
     \caption{ShapeWithSlotsDoubleLevel}
     \label{fig:firstlabel}
   \end{minipage}%
   \begin{minipage}{0.5\textwidth}
     \centering
     \includegraphics[scale=1]{images/shape2.png}
     \caption{ShapeWithSlotsDoubleLevel}
     \label{fig:secondlabel}
   \end{minipage}%
 \end{figure}
share|improve this answer
3  
Leave a little gap between the two figures by (for example) issuing \par\medskip, or better, \par\vspace{\intextsep}, after the first \label. –  Werner Dec 21 '11 at 0:56
    
@Werner: good idea :) –  cmhughes Dec 21 '11 at 1:02

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.