我知道这个问题以前有人问过
不幸的是,那里给出的答案对我没有用。
我正在努力在指定位置实现分页符。
非常感谢您的帮助。
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[ruled,vlined,linesnumbered,onelanguage]{algorithm2e}
\begin{document}
\begin{algorithm}[H]
\SetAlgoLined
\caption{Dummy Algorithm.}
%
Do something. \\
\For{$k=0,1,2,3, ...$}{
Do something. \\
\eIf{$x \geq y$}{
Do something. \\
}{
Do something. \\
\For{$j = 1,...,10$}{
Do something. \\
}
THIS IS THE SPOT WHERE I NEED THE PAGE BREAK.\\
Do something. \\
}
}
\end{algorithm}
\end{document}
答案1
链接答案的方法只有在您可以将算法分解为两个或多个可以单独编译的部分时才有效。您的示例中并非如此。
这种方法是解决这个问题的另一种方法。
(1)使用 将算法生成为独立的 pdf 文件(algo.pdf
在此示例中)algo.tex
。
(2)使用命令的trim
和选项添加算法的顶部部分以裁剪图像的上部。clip
\includegraphics
\includegraphics[trim=left bottom right top, clip]
(以bp为单位。大点为1/72英寸)
将 \clearpage
所有剩余的浮点数添加到排版中,然后包含图形的下半部分,这次选择修剪值来裁剪图像的底部。
最后将算法的计数器增加1。
这是文件 algo.tex
%% File algo.tex
\documentclass[preview]{standalone}
\usepackage[ruled,vlined,linesnumbered,onelanguage]{algorithm2e}
\begin{document}
\begin{algorithm}[H]
\SetAlgoLined
\caption{Dummy Algorithm.}
%
Do something. \\
\For{$k=0,1,2,3, ...$}{
Do something. \\
\eIf{$x \geq y$}{
Do something. \\
}{
Do something. \\
\For{$j = 1,...,10$}{
Do something. \\
}
THIS IS THE SPOT WHERE I NEED THE PAGE BREAK.\\
Do something. \\
}
}
\end{algorithm}
\end{document}
这是完整的代码。
\documentclass[a4paper]{article}
\usepackage[ruled,vlined,linesnumbered,onelanguage]{algorithm2e}% used for the second algorithm
\usepackage{graphicx}
\usepackage[labelsep=none,labelformat=empty]{caption}% empty captions
\usepackage{kantlipsum} % only for dummy text
\begin{document}
1. \kant[1-2]\kant[9]
\noindent
\begin{figure}[bh!]
\centering
\includegraphics[trim=0 43 10 0,clip]{algo.pdf}
\caption{}\label{alg:one}
\end{figure}
\clearpage % typeset all floats
\noindent
\begin{figure}[th!]
\centering
\includegraphics[trim=0 0 10 150,clip]{algo.pdf}
\end{figure}
\stepcounter{algocf}% correct the algorithm number
See listing of Algorithm~\ref{alg:one}.
\bigskip
4. \kant[11]
\begin{algorithm}
\SetAlgoLined
\caption{Another Dummy Algorithm.}
%
Do something. \\
\For{$k=0,1,2,3, ...$}{
Do something. \\
\eIf{$x \geq y$}{
Do something. \\
}{
Do something. \\
\For{$j = 1,...,10$}{
Do something. \\
}
ANOTHER Algorithm.\\
Do something. \\
}
}
\end{algorithm}
\end{document}