3

Occasionally there are "special pages" on which I do not want to have any figures or tables (e.g., cover pages).

Usually I solve this by simply putting all floats sufficiently late in the source code so that they never appear on the special page.

Is there any cleaner solution? Can I easily implement a \nofloatsonthispage macro?

  • 1
    I normally used the placeins package and \FloatBarrier. Related/duplicate question? – Mike Renfro May 18 '14 at 13:16
  • @MikeRenfro: How can you achieve "no floats on this page" with placeins & \FloatBarrier? To me it seems that placeins only helps to make sure that floats are placed near the point in which they appear in the source code, while I would like to do the opposite (do not put floats on this page even if it is possible)? – Jukka Suomela May 18 '14 at 16:06
  • Neither of these options is an exact solution: first, once you know the first page of text, and assuming the floats are relatively large, you can place a \FloatBarrier between two paragraphs near the end of the first page. Second, using the [section] option to the placeins package will force floats defined in a particular section to be placed in that section. If the first section of a chapter has no floats, and takes up around one page, you'll get no floats there. – Mike Renfro May 18 '14 at 16:17
  • 1
    Did you consider omitting the figure or table environment around a specific graph or tabular environment. You could place them basically everywhere and do not bother with floats in this case – user31729 May 18 '14 at 21:09
2

Here is some "bold" code disabling and enabling float placement:

\DeferAllFloats stops float placement from that point onwards for all floats that are not yet placed (i.e., already deferred or encountered later).

\AllowFloats reallows float placement.

In a two-column document those commands act on the column level, e.g., if \AllowFloats is placed somewhere in the first column of the page the second column may receive floats again. Similar to ensure that the next page is not getting any floats one may has to place \DeferAllFloats somewhere near the end of the previous page (to prevent any floats already waiting to be set from being placed).

So perhaps not perfect, but ... (I probably could have gotten away with less settings but that would have required a bit more thinking on dependencies).

\documentclass[twocolumn]{article}

\makeatletter
\newif\if@nofloats
\def\AllowFloats{\global\let\if@nofloats\iffalse}
\def\DeferAllFloats{\global\let\if@nofloats\iftrue\@floatplacement}
\AllowFloats
\AtEndDocument\AllowFloats

\def\@floatplacement{%
 \if@nofloats
   \global\@topnum\z@
    % Textpage bit, global:
   \global\@toproom \z@
   \global\@botnum  \z@
   \global\@botroom \z@
   \global\@colnum  \z@
    % Floatpage bit, local:
   \@fpmin   1.1\@colht
 \else
   \global\@topnum\c@topnumber
    % Textpage bit, global:
   \global\@toproom \topfraction\@colht
   \global\@botnum  \c@bottomnumber
   \global\@botroom \bottomfraction\@colht
   \global\@colnum  \c@totalnumber
    % Floatpage bit, local:
   \@fpmin   \floatpagefraction\@colht
 \fi
}

\def \@dblfloatplacement {%
 \if@nofloats
  \global \@dbltopnum \z@
  \global \@dbltoproom \z@
  \@textmin \@colht
  \@fpmin 1.1\textheight
 \else
  \global \@dbltopnum \c@dbltopnumber
  \global \@dbltoproom \dbltopfraction\@colht
  \@textmin \@colht
  \advance \@textmin -\@dbltoproom
  \@fpmin \dblfloatpagefraction\textheight
  \@fptop \@dblfptop
  \@fpsep \@dblfpsep
  \@fpbot \@dblfpbot
 \fi
}
\makeatother

%%% remainder is for testing

\usepackage{lipsum}
\newcommand\Afloat[1]{\begin{figure}A float\hrulefill\caption{#1}\end{figure}}
\newcommand\Wfloat[1]{\begin{figure*}A wide float\hrulefill\caption{#1}\end{figure*}}

\begin{document}

\lipsum[1]

\Afloat{A}
\Wfloat{B}

\DeferAllFloats
\Afloat{C}

\lipsum[2-21]


XXXX --- here we allow floats again ---

\AllowFloats

\lipsum[3-10]

\end{document}

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.