![需要在单个图形中使用多种算法,并且每种算法都有子标题](https://linux22.com/image/353666/%E9%9C%80%E8%A6%81%E5%9C%A8%E5%8D%95%E4%B8%AA%E5%9B%BE%E5%BD%A2%E4%B8%AD%E4%BD%BF%E7%94%A8%E5%A4%9A%E7%A7%8D%E7%AE%97%E6%B3%95%EF%BC%8C%E5%B9%B6%E4%B8%94%E6%AF%8F%E7%A7%8D%E7%AE%97%E6%B3%95%E9%83%BD%E6%9C%89%E5%AD%90%E6%A0%87%E9%A2%98.png)
\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
以下实现了您的目标 - 在内部设置每个算法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}