# How to avoid splitting tables between sections

I have 5 tables and a section after them. After creation of an output file I have two tables on one page, then a section and last 3 tables on next page.

What I want to achieve is to put tables and section below them.

\begin{table}[ht]\footnotesize
\centering
\begin{tabular}{|ll|}
......
\end{tabular}
\label{tab:result}
\end{table}

\section{Section below tables}

-

You can use the \FloatBarrier macro from the placeins package. This prevents floats from floating across the barrier. Alternatively, you can use the section option to that package to prevent floats from leaving the section.

-
I've used \usepackage[section]{placeins} and \FloatBarrier and tables are in fact above section. The side effect is that last 3 tables that have only one row each, take whole page... Do you have any idea how to avoid this? –  pixel Oct 29 '10 at 20:37
@pixel: You can try using \FloatBarrier in the places you don't want the floats to cross without using the [section] option. But without an example of what's going wrong, I can't really say. –  TH. Oct 30 '10 at 2:16

The easiest way is to use the placeins package:

\usepackage[section]{placeins}

-
Does it work for subsections and subsubsections also ? –  Anusha Nov 4 '14 at 12:55

or you can change \begin{table}[ht] to \begin{table}[H] and add \usepackage{float} to your preamble. the H means "absolutely do not float this, and put it right here."

-
@Will Robertson: My guess is people are so frustrated with LaTeX generally terrible float placement that they want to just say, "put it here, dammit!" One interface that I'd like is a way to say, "put this figure on page x", "put that figure on page x", "put this other figure on page y" and have LaTeX do exactly that: stack the first two figures on page x, and the third on page y. When I get into this position, I tend to move floats into their own files and then \input them and just move the location of the \input statement until LaTeX gives me what I want. It is suboptimal. –  TH. Oct 29 '10 at 3:37
@TH., @Will Robertson: When I was still working with latex (a decade ago), float placement was also one of my major headaches always. The problem with [H] and [!h] was then that you end up having to add a gazillion of them just to prevent the float numbering from going out of order (table 5 appearing before table 4). A very nice feature in ConTeXt is that it automatically renumbers the floats in such a case. Is something like that also possible in latex these days? –  Taco Hoekwater Oct 29 '10 at 6:58
@Taco: Not that I'm aware of, although Will would undoubtably know more. The LaTeX 2e kernel is perfectly willing to place figure 5 before figure 4 by default if one of them is a single column float and the other is a two column float. (In fact, a paper I was proof-reading for someone today had exactly this problem.) The fix is to use the fixltx2e package, but that just ensures the floats go in order; it doesn't renumber them if they're out of order. –  TH. Oct 29 '10 at 7:06
I agree, the H option is pretty brute force, however, I write tech doc in latex for my company (I'm pretty happy they use it!) but I always have a ton of floats, and apparently it's too much to ask the user to turn the page to look at a table or figure. My company hates the htbp and I am forced to use H. But it does exactly what it's supposed to, and is pretty reliable, even if it leaves some suboptimal layouts. –  Mica Oct 29 '10 at 19:40
@Taco @TH I'm just discovering the magic of floats :-) The Tex FAQ page for "non-floating floats" mentions using \Makesorted from the perpage package to make sure the sequence of numbers is correct. (This info could be new since when this question was asked for all I know). –  atomicules Sep 29 '11 at 14:19

If you're using memoir, it includes functionality from placeins. It allows you, for example, to do this:

\setFloatBlockFor{section}


which is equivalent to \usepackage[section]{placeins}

-