[Tex/LaTex] Prevent Float from being placed within a paragraph

floatspositioning

is it possible to prevent a float from being placed within a paragraph? I know there has been another post (How to protect text from being split by a float?) with a similar question, but I would like to allow the float to be placed after the paragraph as well.

This minimal working example (shortened) illustrates what I mean:

\documentclass[a4paper,10pt]{scrreprt}
\usepackage[utf8]{inputenc}

\begin{document}

\begin{figure}[htbp]
   \def\a{ I am a figure}
   \a\\\a\\\a\\\a\\\a\\\a\\\a\\\a\\\a\\\a\\\a
\end{figure}

\begin{figure}[htbp]
    \def\b{I am another figure}
    \b\\\b\\\b\\\b\\\b\\\b\\\b\\\b\\\b\\\b\\\b
\end{figure}

\begin{figure}[htbp]
    \def\c{I am yet another figure}
    \c\\\c\\\c\\\c\\\c\\\c\\\c\\\c\\\c\\\c\\\c
\end{figure}

\def\d{I am text}
\d\\\d\\\d\\\d\\\d\\\d\\\d\\\d\\\d\\\d\\
\d\\\d\\\d\\\d\\\d\\\d\\\d\\\d\\\d\\\d\\
\d\\\d\\\d\\\d\\\d\\\d\\\d\\\d\\\d\\\d\\
\d\\\d\\\d\\\d\\\d\\\d\\\d\\\d\\\d\\\d\\
\d\\\d\\\d\\\d\\\d\\\d\\\d\\\d\\\d\\\d\\
\d\\\d\\\d\\\d\\\d\\\d\\\d\\\d\\\d\\\d\\
\d\\\d\\\d\\\d\\\d\\\d\\\d\\\d\\\d\\\d\\
\d\\\d\\\d\\\d\\\d\\\d\\\d\\\d\\\d\\\d\\
\d\\\d\\\d\\\d\\\d\\\d\\\d\\\d\\\d\\\d\\
\d\\\d\\\d\\\d\\\d\\\d\\\d\\\d\\\d\\\d
\end{document}

Using the solution from the post I linked above, the three figures would be forced to be placed before the text, but I would like to allow the following solution as well:

FIGURE1
FIGURE2
TEXT
FIGURE3

I thought maybe it is possible to place the text in some kind of a boxed environment (page breaks inside the paragraph must be possible).

Best Answer

Changing float placement parameters mid document is a bit fragile, but this works here

\documentclass[a4paper,10pt]{scrreprt}
\usepackage[utf8]{inputenc}
\usepackage{afterpage}
\begin{document}

\begin{figure}[htbp]
   \def\a{ I am a figure}
   \a\\\a\\\a\\\a\\\a\\\a\\\a\\\a\\\a\\\a\\\a
\end{figure}

\begin{figure}[htbp]
    \def\b{I am another figure}
    \b\\\b\\\b\\\b\\\b\\\b\\\b\\\b\\\b\\\b\\\b
\end{figure}

\begin{figure}[htbp]
    \def\c{I am yet another figure}
    \c\\\c\\\c\\\c\\\c\\\c\\\c\\\c\\\c\\\c\\\c
\end{figure}


{\setcounter{totalnumber}{0}
\def\d{I am text}
\d\\\d\\\d\\\d\\\d\\\d\\\d\\\d\\\d\\\d\\
\d\\\d\\\d\\\d\\\d\\\d\\\d\\\d\\\d\\\d\\
\d\\\d\\\d\\\d\\\d\\\d\\\d\\\d\\\d\\\d\\
\d\\\d\\\d\\\d\\\d\\\d\\\d\\\d\\\d\\\d\\
\d\\\d\\\d\\\d\\\d\\\d\\\d\\\d\\\d\\\d\\
\d\\\d\\\d\\\d\\\d\\\d\\\d\\\d\\\d\\\d\\
\d\\\d\\\d\\\d\\\d\\\d\\\d\\\d\\\d\\\d\\
\d\\\d\\\d\\\d\\\d\\\d\\\d\\\d\\\d\\\d\\
\d\\\d\\\d\\\d\\\d\\\d\\\d\\\d\\\d\\\d\\
\d\\\d\\\d\\\d\\\d\\\d\\\d\\\d\\\d\\\d}\afterpage{\setcounter{totalnumber}{3}}

\end{document}
Related Question