30

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}

5 Answers 5

30

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.

2
  • 1
    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, 2010 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, 2010 at 2:16
26

The easiest way is to use the placeins package:

\usepackage[section]{placeins}
1
  • 2
    Does it work for subsections and subsubsections also ?
    – Anusha
    Nov 4, 2014 at 12:55
8

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."

6
  • 2
    @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, 2010 at 3:37
  • 1
    @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? Oct 29, 2010 at 6:58
  • 2
    @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, 2010 at 7:06
  • 1
    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, 2010 at 19:40
  • 1
    @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, 2011 at 14:19
5

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}

1

The simple \clearpage command just before the new section (after the table) seems to work nicely. (in this case \clearpage does not insert an empty page)

\afterpage{...} worked OK but hid the section from the contents section of my thesis.

\section{Name1}
Stuff
\begin{table}[h]
...
\end{table}[h]
\clearpage
\section{Name2}
Stuff 2
\begin{table}[h]
...
\end{table}[h]
1
  • While this might somehow be a fragment of an answer, it's a fragment only
    – user31729
    Sep 18, 2015 at 20:28

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .