LATEX algorithm總跑到最後一頁(愛思唯爾模板),或者過長,分頁顯示
阿新 • 來源:網路 • 發佈:2022-12-30
新增如下命令到匯入包區
\usepackage{algorithm}
\usepackage{algorithmic}
\renewcommand{\algorithmicrequire}{ \textbf{Input:}} %Use Input in the format of Algorithm
\renewcommand{\algorithmicensure}{ \textbf{Output:}} %UseOutput in the format of Algorithm
\usepackage{float}
\usepackage{lipsum}
\makeatletter
\newenvironment{breakablealgorithm}
{% \begin{breakablealgorithm}
\begin{center}
\refstepcounter{algorithm}% New algorithm
\hrule height.8pt depth0pt \kern2pt% \@[email protected] for \@[email protected]
\renewcommand{\caption}[2][\relax]{% Make a new \caption
{\raggedright\textbf{\[email protected]~\thealgorithm} ##2\par}%
\ifx\relax##1\relax % #1 is \relax
\addcontentsline{loa}{algorithm}{\protect\numberline{\thealgorithm}##2}%
\else % #1 is not \relax
\addcontentsline{loa}{algorithm}{\protect\numberline{\thealgorithm}##1}%
\fi
\kern2pt\hrule\kern2pt
}
}{% \end{breakablealgorithm}
\kern2pt\hrule\relax% \@[email protected] for \@[email protected]
\end{center}
}
\makeatother
正文演算法部分
\begin{breakablealgorithm}
\caption{The caption.}
\label{alg:coherence}
\begin{algorithmic}[1] %這個1 表示每一行都顯示數字
\begin{footnotesize} %%調整演算法字型大小
\REQUIRE ~~\\ %演算法的輸入引數:Input
The target word for $t$ timestep, $w_t^*$;\\
The sentence where the target word is located, $S_k$;\\
The final distribution from which to predict word for $t$ timestep, $P(w)$;\\
The balance weight, $\lambda$;
\ENSURE ~~\\ %演算法的輸出:Output
The final objective for $t$ timestep, $Loss_t$;
\STATE compute the probability
\ENDIF
\RETURN $Loss_t$; %演算法的返回值
\end{footnotesize}
\end{algorithmic}
\end{breakablealgorithm}

