
나는 항상 처음 참조된 단락의 끝에 내 부동 환경을 배치했습니다.
하지만 단락이 두 페이지(첫 번째 페이지 하단에서 시작하여 두 번째 페이지 상단에서 끝나는)로 분할되면 문제가 발생합니다. 이 페이지에도 플로트가 있더라도 첫 페이지에 있는 문단의 첫 번째 문장에서 직접 참조되기 때문에 플로트를 첫 페이지 상단에 쉽게 배치할 수 있습니다. 그러나 Latex는 두 번째 페이지에 플로트를 배치하여 첫 번째 페이지의 절반이 비어 있고(플로트가 누락되었기 때문에) 두 번째 페이지의 절반이 비어 있습니다(이제 플로트가 이 페이지의 유일한 항목이기 때문에).
단락 앞의 소스에서 부동 환경을 수동으로 이동하는 것보다 더 쉬운 방법이 있습니까(위에서 언급한 조건이 더 이상 유지되지 않는 경우, 예를 들어 추가 텍스트가 삽입되는 경우 모든 문제가 발생함)?
MWE(두 번째 페이지에 부동 소수점 포함)
\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(첫 번째 페이지에 플로트 포함)
\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}
답변1
매크로 이름을 다시 사용하려면 \renewcommand를 두 번째로 사용하세요.
\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}