\documentclass{article}
\usepackage{algorithm,algpseudocode}
\algtext*{EndIf}% Remove \EndIf
\renewcommand{\thealgorithm}{}
\usepackage{amsmath,amssymb}
\usepackage{subcaption}
\usepackage{comment}
\begin{document}
\begin{algorithm}
\caption{$Game PrvInd_{G,\phi}$}
\label{pseudoPSO}
\begin{algorithmic}
\Procedure{Garble}{$f_0, f_1, x_0, x_1$}
\If{$f(\phi(f0) \neq\phi(f1)$}
\Return $\perp$ \EndIf
\If {$ev(f_0, x_0) \neq ev(f_1, x_1)$}
\Return $\perp$ \EndIf
\If{$\{x_0,x_1\} \nsubseteq \{0,1\}^{{f_0}.n}$} \Return $\perp$ \EndIf
$(F, e, d) \leftarrow Gb(1^k, f_b)$;
$X \leftarrow En(e, x_b)$
\Return (F,X, d)
\EndProcedure
\end{algorithmic}
\end{algorithm}
\begin{algorithm}
\caption{$Game PrvInd_{G,\phi,S}$}
\label{pseudoPSO}
\begin{algorithmic}
\Procedure{Garble}{f,x,}
\If{$x\notin\{0,1\}^{{f}.n}$}
\Return $\perp$ \EndIf
\If {b=1}
$(F, e, d) \leftarrow Gb(1^k, f)$;
$X \leftarrow En(e, x)$
\Else $ y \leftarrow ev(f, x); (F,X, d) \leftarrow S(1^k, y,\phi(f))$
\EndIf
\Return (F,X, d)
\EndProcedure
\end{algorithmic}
\end{algorithm
\end{document}
我想在單一圖表中顯示多個演算法,並在右側顯示每個演算法的子標題,如下圖所示:
但我得到的是這個(只顯示前兩個演算法:)
我還需要使用其他函式庫嗎
答案1
以下實現了您的目標 - 在 a 中設定每個演算法tabular
(以應用適當的規則(頂部和底部),然後您可以僅使用環境algorithmic
來設定偽代碼:
\documentclass{article}
\usepackage[margin=0.5in]{geometry}
\usepackage{algorithm,algpseudocode,amsmath,amssymb}
\algtext*{EndIf}% Remove \EndIf
\renewcommand{\thealgorithm}{}
\begin{document}
\begin{figure}
\begin{tabular}[t]{@{} p{.49\linewidth} @{}}
\hline
\begin{algorithmic}
\Procedure{Garble}{$f_0, f_1, x_0, x_1$}\hfill $\text{Game PrvInd}_{G,\phi}$
\If{$f(\phi(f0) \neq \phi(f1))$} \Return $\perp$
\EndIf
\If{$\text{ev}(f_0, x_0) \neq \text{ev}(f_1, x_1)$} \Return $\perp$
\EndIf
\If{$\{x_0,x_1\} \nsubseteq \{0,1\}^{{f_0} \cdot n}$} \Return $\perp$
\EndIf
\State $(F, e, d) \leftarrow \text{Gb}(1^k, f_b)$;
$X \leftarrow \text{En}(e, x_b)$
\Return $(F, X, d)$
\EndProcedure
\end{algorithmic} \\
\hline
\end{tabular}\hfill
\begin{tabular}[t]{@{} p{.49\linewidth} @{}}
\hline
\begin{algorithmic}
\Procedure{Garble}{$f,x$}\hfill $\text{Game PrvInd}_{G,\phi,S}$
\If{$x \notin \{0,1\}^{{f} \cdot n}$} \Return $\perp$
\EndIf
\If{$b = 1$} $(F, e, d) \leftarrow \text{Gb}(1^k, f)$;
$X \leftarrow \text{En}(e, x)$
\Else{} $y \leftarrow \text{ev}(f, x)$; $(F, X, d) \leftarrow S(1^k, y, \phi(f))$
\EndIf
\State \Return $(F, X, d)$
\EndProcedure
\end{algorithmic} \\
\hline
\end{tabular}
\caption{Some games and their definitions.}
\end{figure}
\end{document}