
Ich platziere meine Float-Umgebungen immer am Ende des Absatzes, in dem sie zum ersten Mal referenziert wurden.
Ich habe jedoch ein Problem, wenn der Absatz auf zwei Seiten aufgeteilt ist (beginnend am unteren Ende der ersten Seite und endend am oberen Ende der zweiten Seite). Der Float könnte problemlos am oberen Ende der ersten Seite platziert werden, da er direkt im ersten Satz des Absatzes referenziert wird, der sich auf der ersten Seite befindet, auch wenn sich der Float auch auf dieser Seite befindet. Aber Latex platziert den Float auf der zweiten Seite, was zu einer halb leeren ersten Seite (aufgrund des jetzt fehlenden Floats) und einer halb leeren zweiten Seite (weil der Float jetzt das Einzige auf dieser Seite ist) führt.
Gibt es eine einfachere Möglichkeit, als die Float-Umgebung in der Quelle manuell vor den Absatz zu verschieben (mit all den Problemen, wenn die oben genannte Bedingung nicht mehr gilt, z. B. wenn zusätzlicher Text eingefügt wird)?
MWE (mit dem Float auf der zweiten Seite)
\documentclass{article}
\usepackage{algorithm2e}
\usepackage[nopar]{lipsum}
\begin{document}
\null
\vfill
\lipsum[1-3]
In the first sentence I reference the float~\ref{alg:Algo}. After the first sentence there are many more sentences and the float ist put after the whole paragraph. After the first sentence there are many more sentences and the float ist put after the whole paragraph. After the first sentence there are many more sentences and the float ist put after the whole paragraph. After the first sentence there are many more sentences and the float ist put after the whole paragraph. After the first sentence there are many more sentences and the float ist put after the whole paragraph.
\begin{algorithm}[tbp]
\SetKwInOut{Input}{Input}
\SetKwInOut{Output}{Output}
\LinesNumbered
\caption{Caption}
\label{alg:Algo}
\Input{-}
\Output{-}
\BlankLine
First Line\;
First Line\;
First Line\;
First Line\;
First Line\;
\Return{result}\;
\end{algorithm}
\end{document}
MWE (mit dem Float auf der ersten Seite)
\documentclass{article}
\usepackage{algorithm2e}
\usepackage[nopar]{lipsum}
\begin{document}
\null
\vfill
\lipsum[1-3]
\begin{algorithm}[tbp]
\SetKwInOut{Input}{Input}
\SetKwInOut{Output}{Output}
\LinesNumbered
\caption{Caption}
\label{alg:Algo}
\Input{-}
\Output{-}
\BlankLine
First Line\;
First Line\;
First Line\;
First Line\;
First Line\;
\Return{result}\;
\end{algorithm}
In the first sentence I reference the float~\ref{alg:Algo}. After the first sentence there are many more sentences and the float ist put after the whole paragraph. After the first sentence there are many more sentences and the float ist put after the whole paragraph. After the first sentence there are many more sentences and the float ist put after the whole paragraph. After the first sentence there are many more sentences and the float ist put after the whole paragraph. After the first sentence there are many more sentences and the float ist put after the whole paragraph.
\end{document}
Antwort1
Um den Makronamen wiederzuverwenden, verwenden Sie \renewcommand das zweite Mal.
\documentclass{article}
\usepackage{algorithm2e}
\usepackage[nopar]{lipsum}
\begin{document}
\null\vfill
\lipsum[1-3]
\newcommand{\InsertAlgorithmHere}{%
\begin{algorithm}[tbp]
\SetKwInOut{Input}{Input}
\SetKwInOut{Output}{Output}
\LinesNumbered
\caption{Caption}
\label{alg:Algo}
\Input{-}
\Output{-}
\BlankLine
First Line\;
First Line\;
First Line\;
First Line\;
First Line\;
\Return{result}\;
\end{algorithm}}
In the first sentence I reference the float~\ref{alg:Algo}.\InsertAlgorithmHere
After the first sentence there are many more sentences and the float ist put after the whole paragraph.
After the first sentence there are many more sentences and the float ist put after the whole paragraph.
After the first sentence there are many more sentences and the float ist put after the whole paragraph.
After the first sentence there are many more sentences and the float ist put after the whole paragraph.
After the first sentence there are many more sentences and the float ist put after the whole paragraph.
\end{document}