1

I am finding it a bit difficult to keep the tables where I wanted them. I can't seen to make a MWE either. But the document is uploaded here.

Basically, say the

text (~\ref{}) is on page 70 and the actual table is on 84;

text (~\ref{}) is on page 71 and the actual table is on 85;

text (~\ref{}) is on page 72 and the actual table is on 86;

where

\begin{table}[!hp]

has been used at the beginning of all tables.

In all cases, the text are in \subsection{}s. The tables seem to have been flushed to the end of the whole section.

What I hope to get is, the tables are close to the text, if not the maybe on the next page. But a simple !hp is not working at all.

  • 2
    Just to inform, there is a command \pageref{}, if you wish. – Sigur Feb 20 '15 at 19:13
  • 1
    the optional argument is preventing the float being placed at the top (which is the usual place) or bottom of any page so makes it far more likely the float drifts a long way off. Did you need to avoid t and b? – David Carlisle Feb 20 '15 at 19:14
  • 1
    @ChenStatsYu, you can define a new command just to ref tables: \newcommand{\reftab}[1]{Table~\ref{#1}~(pg.~\pageref{#1})}. Then just write see \reftab{foo}... – Sigur Feb 20 '15 at 19:25
  • 2
    @ChenStatsYu: You're probably interested in the latter of the following FAQs: How to influence the position of float environments like figure and table in LaTeX? and Keeping tables/figures close to where they are mentioned – Werner Feb 20 '15 at 19:28
  • 1
    if your tables are just over half page high and so you can not get two on to a float page, then unless \floatpagefraction is low enough to allow just one float, no float pages can be made and as you have prevented t and b that means no floats can be positioned so they all stack until flushed by a \clearpage – David Carlisle Feb 20 '15 at 19:31
5

There is general advice (mostly in Will's answer) in an earlier question

However you have a specific requirement (for some reason) to avoid text page floats and only allow h and p.

That makes positioning difficult. If a float cannot go "here" (and that is usually the case as that point is too low on the page to fit in a float) then LaTeX will hold it back to make a float page. To avoid very empty pages it waits until it has at least \floatpagefraction of a page (this fraction is not ignored if you use !). By default in article this is 0.5 so at least half the page must be filled.

This means that if you have two figures with the first just less than half a page in height then in around half the cases they will not fit "here" as that point will be in the bottom half of the page. The first float cannot make a float page as the page will be too short, but the two figures will not fit on a float page if the second one is larger, or even if it is smaller but there is no room for two figures and the \floatsep gap between. This means a setting of [hp] makes it very easy to get floats that cannot be placed, and as all figures are kept in order, once one cannot be placed they are all unplaceable. They will then be held back until flushed with a \clearpage at the end of the document or section.

So with an option of [hp] you must set \floatpagefraction low enough that any sequence of floats can be placed.

Simplest is to set it really low, say to 0.01. Then no float should float more than one page; it will always be shipped out immediately. However, because floats are not held back, the float pages will only have one float per page as latex will not wait to see if the next one fits.

  • @Ian thanks for fixing my approximation to English:-) – David Carlisle Feb 20 '15 at 23:43
1

There are several ways to keep floating objects closer to their position.

See this great answer to how float objects work:

https://tex.stackexchange.com/a/39020/59716

With the optional placement instruction [!hp] you will gain not much. You take away some choices for LaTeX to place the float objects, namely b and t, and add ! and h.

The standard placement if you give no option is btp, you can change this default with the float package:

\usepackage{float} \floatplacement{table}{htbp}

to add the h as default.

Another package that helps is placeins, which offers the command \FloatBarrier, which forces all current floats to be placed before it.

If you load it like this:

\usepackage[section, below]{placeins}

a float will never run on a page not belonging to its section.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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