1、注释掉默认的引用
% \usepackage{algorithmic}
% \usepackage{algorithm}
2、在\begin{document}之前加以下内容
\usepackage[ruled,norelsize,vlined,linesnumbered]{algorithm2e}
\makeatletter
\newcommand{\removelatexerror}{\let\@latex@error\@gobble}
\makeatother
3、写具体的算法
	\begin{figure}[!t]
		\label{alg:LSB}
		\renewcommand{\algorithmicrequire}{\textbf{Input:}}
		\renewcommand{\algorithmicensure}{\textbf{Output:}}
		\removelatexerror
		\begin{algorithm}[H]
			\caption{algorithm caption}%算法名字
			\LinesNumbered %要求显示行号
			\KwIn{input parameters A, B, C}%输入参数
			\KwOut{output result}%输出
			some description\; %\;用于换行
			\For{condition}{
				only if\;
				\If{condition}{
					1\;
				}
			}
			\While{not at end of this document}{
				if and else\;
				\eIf{condition}{
					1\;
				}{
					2\;
				}
			}
			\ForEach{condition}{
				\If{condition}{
					1\;
				}
			}
		\end{algorithm}
	\end{figure}
4、效果
参考:
 https://blog.csdn.net/weixin_43981621/article/details/124824092
 https://blog.csdn.net/mushuiliu/article/details/106069328



















