1. 程式人生 >實用技巧 >其它 >LATEX algorithm總跑到最後一頁(愛思唯爾模板),或者過長,分頁顯示

LATEX algorithm總跑到最後一頁(愛思唯爾模板),或者過長,分頁顯示


新增如下命令到匯入包區

\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}

ref:LATEX演算法過長,分頁顯示(基於愛思唯爾模板)(解決演算法老是跑到最後一頁的問題)_獵人伯爵-CSDN部落格主要內容從以下連結轉載:版權宣告:本文為rechardchen123博主原創文章,遵循 CC 4.0 BY-SA 版權協議,轉載請附上原文出處連結和本宣告。本文連結:https://blog.csdn.net/rechardchen123/article/details/78859173內容主要基於上述引用,但是上述引用在使用愛思唯爾模板的時候有些問題。下面給出可用的程式碼。設定環境:\usepackage{algorithm}\usepackage{algorithmic}\.

LATEX algorithm總跑到最後一頁(愛思唯爾模板),或者過長,分頁顯示

https://blog.csdn.net/weixin_43914200/article/details/107039162