I have two algorithms wrote by the algorithm2e package. One of them is large and the other is small. My try is here:
%\documentclass[runningheads,a4paper]{llncs}
\documentclass{article}
\usepackage{amssymb}
\usepackage{graphicx}
\usepackage{subfigure}
\usepackage{amsmath}
\usepackage[noline]{algorithm2e}
\begin{document}
%%my first try by using minipage
\begin{minipage}{\linewidth}
\begin{center}
\begin{minipage}{0.65\linewidth}
\begin{algorithm}[H]
\DontPrintSemicolon
\SetKwProg{Fn}{Function}{}{end}
\Fn{$u^h \leftarrow $V-cycle($A_h, u_0^h, f_h$)}{
\uIf{$h==h_0$}{\KwRet{$u_h \leftarrow A_h^{-1}f_h $}\tcc*[r]{bottom solve}}
$u^h \leftarrow \text{smooth}(A_h,u_0^h,f_h)$\tcc*[r]{pre-smooth}
$r^h \leftarrow f_h-A_hu^h$\tcc*[r]{residual}
$r^{2h} \leftarrow I_h^{2h}r^h$\tcc*[r]{restriction}
$\delta^{2h} \leftarrow \text{V-cycle}(A_{2h},0,r^{2h})$\tcc*[r]{recursive call}
$u^h \leftarrow u^h + I_{2h}^h\delta^{2h}$\tcc*[r]{interpolation}
$u^h \leftarrow \text{smooth}(A_{2h},u^h,f_h)$\tcc*[r]{post-smooth}
\KwRet{$u^h$}\;
}
\caption{V-cycle}
\end{algorithm}
\end{minipage}%
\begin{minipage}{0.35\linewidth}
\begin{algorithm}[H]
\DontPrintSemicolon
$h \leftarrow h_0$\;
$u^h \leftarrow A_h^{-1}f_h$\;
\While{!done}{
$u^{h/2} \leftarrow \overline{I}_h^{h/2}u^h$\;
$h \leftarrow \frac{h}{2}$\;
$u^h \leftarrow \text{V-cycle}(A_h,u^h,f_h)$\;
}
\caption{F-cycle}
\end{algorithm}
\end{minipage}
\end{center}
\end{minipage}
%%my second try by using subfigure and minipage
\begin{figure}
\begin{center}
\subfigure[V-cycle]{
\begin{minipage}{0.7\linewidth}
\begin{algorithm}[H]
\DontPrintSemicolon
\SetKwProg{Fn}{Function}{}{end}
\Fn{$u^h \leftarrow $V-cycle($A_h, u_0^h, f_h$)}{
\uIf{$h==h_0$}{\KwRet{$u_h \leftarrow A_h^{-1}f_h $}\tcc*[r]{bottom solve}}
$u^h \leftarrow \text{smooth}(A_h,u_0^h,f_h)$\tcc*[r]{pre-smooth}
$r^h \leftarrow f_h-A_hu^h$\tcc*[r]{residual}
$r^{2h} \leftarrow I_h^{2h}r^h$\tcc*[r]{restriction}
$\delta^{2h} \leftarrow \text{V-cycle}(A_{2h},0,r^{2h})$\tcc*[r]{recursive call}
$u^h \leftarrow u^h + I_{2h}^h\delta^{2h}$\tcc*[r]{interpolation}
$u^h \leftarrow \text{smooth}(A_{2h},u^h,f_h)$\tcc*[r]{post-smooth}
\KwRet{$u^h$}\;
}
\end{algorithm}
\end{minipage}
}%
\subfigure[F-cycle]{
\begin{minipage}{0.3\linewidth}
\begin{algorithm}[H]
\DontPrintSemicolon
$h \leftarrow h_0$\;
$u^h \leftarrow A_h^{-1}f_h$\;
\While{!done}{
$u^{h/2} \leftarrow \overline{I}_h^{h/2}u^h$\;
$h \leftarrow \frac{h}{2}$\;
$u^h \leftarrow \text{V-cycle}(A_h,u^h,f_h)$\;
}
\end{algorithm}
\end{minipage}
}
\end{center}
\caption{V-cycle and F-cycle}
\end{figure}
\end{document}
The result of the above is:
Both of them doesn't look very well for me. I want
- The code line will not be broke into two lines.
- Comments will be on the same line with the code.
- Captions of these algorithms are aligned.
Here is my want: