我正在完成我的论文,正在努力让这些算法正确显示...我也刚开始用 LaTeX 编写伪代码,所以非常欢迎任何建议。
\begin{minipage}{0.46\textwidth}
\begin{algorithm}[H]
\centering
\caption{Thistlethwaite's IDDFS}\label{algorithm:iddfsalgorithm}
\footnotesize
\begin{algorithmic}[1]
\Function{searchAllAtDepth}{search depth}
\State{Initialise Cloned Cube Object using 3D Cube as reference}
\If{$depth = 1$}
\For{every move available in the current solving stage}
\State{Reset Cube Object and store to temporary cube variable}
\State{Apply move to cube}
\If{\Call{prune}{method, cube, depth, solving stage}} \Comment{Checks if the current cube state is worth pursuing further solutions for}
\State{Skip the current loop iteration}
\EndIf
\If{\Call{stage}{current cube state}}
% \Comment{If the current cube state fulfils the current solving stage requirements, append the accumulated moves to the overall solution}
\State{\Call{appendSolution}{move}}
\EndIf
\EndFor
\Else
\State{\Call{Search}{move prefix, search depth}}
% \Comment{Figures out the next move to add to the prefix}
\EndIf
\EndFunction
\end{algorithmic}
\end{algorithm}
\end{minipage}
\hfill
\begin{minipage}{0.46\textwidth}
\begin{algorithm}[H]
\centering
\caption{Main Recursive Search Method for IDDFS}
\footnotesize
\begin{algorithmic}[1]
\Function{Search}{Move prefix, search depth}
\State{Initialise fresh cube object}
\State{Apply the move prefix to the cube}
\If{\Call{prune}{method, cube, depth, solving stage}}
\State{\Return}
\EndIf
\If{$depth = 0$}
\If{\Call{Stage}{current cube state}}
\State{Append moves to solution}
\State{\Return}
\EndIf
\Else
\For{every move available in current solving stage}
\Call{Search}{move prefix + move, current depth -1}
\State{Increment nodes value}
\EndFor
\EndIf
\EndFunction
\end{algorithmic}
\end{algorithm}
\end{minipage}
谢谢!
答案1
将整个对偶算法构造设置在 a 内部figure
(以便它可以按照预期的方式浮动),然后使用minipage
非浮动的 s algorithm
(通过[H]
浮点说明符)将它们包含在 内figure
。
\documentclass{article}
\usepackage{algorithm,algpseudocode}
\begin{document}
\begin{figure}
\begin{minipage}[t]{0.48\textwidth}
\begin{algorithm}[H]
\centering
\caption{Thistlethwaite's IDDFS}\label{algorithm:iddfsalgorithm}
\footnotesize
\begin{algorithmic}[1]
\Function{searchAllAtDepth}{search depth}
\State{Initialise Cloned Cube Object using 3D Cube as reference}
\If{$depth = 1$}
\For{every move available in the current solving stage}
\State{Reset Cube Object and store to temporary cube variable}
\State{Apply move to cube}
\If{\Call{prune}{method, cube, depth, solving stage}} \Comment{Checks if the current cube state is worth pursuing further solutions for}
\State{Skip the current loop iteration}
\EndIf
\If{\Call{stage}{current cube state}}
% \Comment{If the current cube state fulfils the current solving stage requirements, append the accumulated moves to the overall solution}
\State{\Call{appendSolution}{move}}
\EndIf
\EndFor
\Else
\State{\Call{Search}{move prefix, search depth}}
% \Comment{Figures out the next move to add to the prefix}
\EndIf
\EndFunction
\end{algorithmic}
\end{algorithm}
\end{minipage}
\hfill
\begin{minipage}[t]{0.48\textwidth}
\begin{algorithm}[H]
\centering
\caption{Main Recursive Search Method for IDDFS}
\footnotesize
\begin{algorithmic}[1]
\Function{Search}{Move prefix, search depth}
\State{Initialise fresh cube object}
\State{Apply the move prefix to the cube}
\If{\Call{prune}{method, cube, depth, solving stage}}
\State{\Return}
\EndIf
\If{$depth = 0$}
\If{\Call{Stage}{current cube state}}
\State{Append moves to solution}
\State{\Return}
\EndIf
\Else
\For{every move available in current solving stage}
\Call{Search}{move prefix + move, current depth -1}
\State{Increment nodes value}
\EndFor
\EndIf
\EndFunction
\end{algorithmic}
\end{algorithm}
\end{minipage}
\end{figure}
\end{document}
删除 s 之间的空行,minipage
以使它们适合同一行,否则 TeX 会插入段落间隙。