# figure environment and contiguous images [duplicate]

Possible Duplicate:
How do I ensure that figures appear in the section they're associated with?

I have a set of images and I want them all to appear in the same \section of my document, obviously in the section I "defined" them. The problem is that, using the figure environment, some images are spreading inside the next section. Something like this:

*start of section n*
IMG 1
IMG 2
...

*start of section n+1*
IMG N-M
...
IMG N

I want to force all N images on staying inside the n-th section. How can I do this? The code I wrote is something like this:

\section{n}

some text

\begin{figure}[ht]
...
\end{figure}
\begin{figure}[ht]
...
\end{figure}
\begin{figure}[ht]
... n-th figure here
\end{figure}

\section{n+1}
-

## marked as duplicate by lockstep, Claudio Fiandrino, qubyte, Marco Daniel, zerothOct 10 '12 at 10:06

Welcome to TeX.sx! This question is very similar to tex.stackexchange.com/questions/279/…. Please take a look at it as the information there might help you. If so, that's great, and we'll probably close this question as a duplicate just to keep the place tidy and to help people find answers quickly. If not, please edit your question here to explain why so that people can better focus their attention to help you. –  lockstep Oct 10 '12 at 8:16
Thanks. Both that thread and David post helped me to solve it. But now I got another problem and I'll see if David is able to help me again. So please don't close this just yet. –  Kei Oct 10 '12 at 8:41
Ok. You can close it now :) –  Kei Oct 10 '12 at 8:49

Using [ht] increases the chance that they float to the end of the document so outside the section. Always include p to give LaTeX a chance. If you load the placeins package it has an option to keep floats in each section.

Also if you want a sequence of small figures on the same page you probably want to increase the number of floats allowed on a page which in article is:

\setcounter{topnumber}{2}
\setcounter{bottomnumber}{1}
\setcounter{totalnumber}{3}
-
That worked, thanks. But now I have another problem. The last image ended up being alone in a page, and instead of being on the top of the page, it is on the center. I tried using [t] instead of [ht], but it didn't help. Any clues? –  Kei Oct 10 '12 at 8:40
Ok. Thanks again. –  Kei Oct 10 '12 at 8:46
it was presumably a p float. Page floats are by default vertically centred but you can change that with \makeatletter\setlength\@fptop{0pt}\makeatother –  David Carlisle Oct 10 '12 at 8:50
Another problem... The first image went backwards in the document and ended up in the previous section. Awkward. –  Kei Oct 10 '12 at 8:53
flafter package –  David Carlisle Oct 10 '12 at 8:55