# 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. –  kikou Oct 10 '12 at 8:41
Ok. You can close it now :) –  kikou 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? –  kikou Oct 10 '12 at 8:40
Ok. Thanks again. –  kikou 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. –  kikou Oct 10 '12 at 8:53
flafter package –  David Carlisle Oct 10 '12 at 8:55
{"extraction_info": {"found_math": true, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 0, "mathjax_display_tex": 0, "mathjax_asciimath": 1, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0, "katex": 0, "math-container": 0, "wp-katex-eq": 0, "align": 0, "equation": 0, "x-ck12": 0, "texerror": 0, "math_score": 0.7307360768318176, "perplexity": 1235.806951989425}, "config": {"markdown_headings": true, "markdown_code": true, "boilerplate_config": {"ratio_threshold": 0.18, "absolute_threshold": 20, "end_threshold": 15, "enable": true}, "remove_buttons": true, "remove_image_figures": true, "remove_link_clusters": true, "table_config": {"min_rows": 2, "min_cols": 3, "format": "plain"}, "remove_chinese": true, "remove_edit_buttons": true, "extract_latex": true}, "warc_path": "s3://commoncrawl/crawl-data/CC-MAIN-2014-49/segments/1416400378724.10/warc/CC-MAIN-20141119123258-00112-ip-10-235-23-156.ec2.internal.warc.gz"}