我已经使用算法环境编写了与照片类似的伪代码,并获得了一些非常好的结果
这是相应的乳胶代码
\begin{algorithm}
\caption{Find the missing number (A, l, r)}
\begin{algorithmic}[1]
\Function{ModifiedBinarySearch}{$A, r, l$}{
\State{m$\gets\lfloor\frac{l+r}{2}\rfloor$}
\If{$r = l$}
\State\Return{m}
\ElsIf{$A[m] = m$}
\State\Call{ModifiedBinarySearch}{A, m + 1, r}
\ElsIf{$A[m] = m - 1$}
\State\Call{ModifiedBinarySearch}{A, l, m \text{-} 1}
\State\Call{ModifiedBinarySearch}{A, m + 1, r}
\ElsIf{$A[m] = m - 2$}:
\State\Call{ModifiedBinarySearch}{A, l, m \text{-} 1}
\EndIf{}
}
\EndFunction{}
\end{algorithmic}
\end{algorithm}
但它会遇到一些问题,如果有新的页面它就不能中断,所以我找到了一个有用的东西,叫做可破坏算法环境设置如下所示
\newenvironment{breakablealgorithm}
{% \begin{breakablealgorithm}
\begin{center}
\refstepcounter{algorithm}% New algorithm
\hrule height.8pt depth0pt \kern2pt% \@fs@pre for \@fs@ruled
\renewcommand{\caption}[2][\relax]{% Make a new \caption
{\raggedright\textbf{\fname@algorithm~\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% \@fs@post for \@fs@ruled
\end{center}
}
\makeatother
上面的是正常算法环境,下面的是 breakablealgorithm 环境,我怎样才能使它更加一致,因为 breakablealgorithm 的格式很差,增加了一些冗余缩进