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*

*start of section n+1*

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:


       some text

        ... n-th figure here

  • 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. – KevinRGT Oct 10 '12 at 8:41
  • Ok. You can close it now :) – KevinRGT 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:

| improve this answer | |
  • 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? – KevinRGT Oct 10 '12 at 8:40
  • 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. – KevinRGT Oct 10 '12 at 8:53
  • flafter package – David Carlisle Oct 10 '12 at 8:55

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