![将两个算法放入两列](https://linux22.com/image/291367/%E5%B0%86%E4%B8%A4%E4%B8%AA%E7%AE%97%E6%B3%95%E6%94%BE%E5%85%A5%E4%B8%A4%E5%88%97.png)
我有单列页面。我想将我的两个算法添加到两列中。我该怎么做?我的算法如下。
\begin{algorithm}[h]
\caption{Resolve 1}
\begin{algorithmic}
\scriptsize
\STATE $ P_i $ sends $ id,t_1,t_2,P_j,h_j $ to TTP where $ P_j $ is the party that does not send $ V_j^{(2)} $ to $ P_i $, TTP does the following and sends the returned message to $P_i$:
\IF{$ currenttime > t_1 $}
\STATE \textbf{send} $ msg $ ``Abort Resolve 1"
\ELSE
\IF { Search($ id, t_1, t_2 $) == NULL }
\STATE \lst = Create($ id, t_1, t_2 $)
\STATE \slst = Create($ id, t_1, t_2 $)
\STATE \lst.add($ P_i, (P_j,h_j) $)
\STATE \textbf{send} $ msg $ ``Come after $ t_2 $"
\ELSE
\STATE \lst.add($ P_i, (P_j,h_j $))
\STATE \textbf{send} $ msg $ ``Come after $ t_2 $"
\ENDIF
\ENDIF
\end{algorithmic}
\end{algorithm}
\begin{algorithm}[h]
\caption{Resolve 3}
\begin{algorithmic}
\scriptsize
\STATE $ P_i $ comes either to receive decryption of a $ \{V^(2)_t\}_{t \in M} $ where $ M \subseteq N $ or his desired decryption shares from TTP's record.
\STATE $ condition $ = \lst.isEmpty()
\IF {$ condition $ is false }
\STATE \textbf{send} msg ``Protocol is aborted"
\ELSE
\IF {$ P_i $ give $\{V^(2)_t\}_{t \in M} $}
\FORALL {$ t $ in $ M $}
\STATE \textbf{send} Decrypt($ sk, V^(2)_t $)
\ENDFOR
\ELSE
\FORALL {$ t $ in $ \slst $ as $ (P_i, shares_t) $}
\STATE \textbf{send} $ shares_t $
\ENDFOR
\ENDIF
\ENDIF
\end{algorithmic}
\end{algorithm}
答案1
你的意思是像这样吗?我在算法之间使用了mulitcols
insidealgorithmic
和 a \columnbreak
。请注意,只有一个 caption 命令可用。
\documentclass{article}
\usepackage{algorithm,algorithmic,multicol}
\begin{document}
\begin{algorithm}[h]
\caption{Resolve 1 and 3}
\begin{multicols}{2}
\begin{algorithmic}
\scriptsize
\STATE $ P_i $ sends $ id,t_1,t_2,P_j,h_j $ to TTP where $ P_j $ is the party that does not send $ V_j^{(2)} $ to $ P_i $, TTP does the following and sends the returned message to $P_i$:
\IF{$ currenttime > t_1 $}
\STATE \textbf{send} $ msg $ ``Abort Resolve 1"
\ELSE
\IF { Search($ id, t_1, t_2 $) == NULL }
\STATE lst = Create($ id, t_1, t_2 $)
\STATE slst = Create($ id, t_1, t_2 $)
\STATE lst.add($ P_i, (P_j,h_j) $)
\STATE \textbf{send} $ msg $ ``Come after $ t_2 $"
\ELSE
\STATE logical lst.add($ P_i, (P_j,h_j $))
\STATE \textbf{send} $ msg $ ``Come after $ t_2 $"
\ENDIF
\ENDIF
\end{algorithmic}
\columnbreak
\begin{algorithmic}
\scriptsize
\STATE $ P_i $ comes either to receive decryption of a $ \{V^(2)_t\}_{t \in M} $ where $ M \subseteq N $ or his desired decryption shares from TTP's record.
\STATE $ condition $ = lst.isEmpty()
\IF {$ condition $ is false }
\STATE \textbf{send} msg `Code`
`Protocol is aborted"
\ELSE
\IF {$ P_i $ give $\{V^(2)_t\}_{t \in M} $}
\FORALL {$ t $ in $ M $}
\STATE \textbf{send} Decrypt($ sk, V^(2)_t $)
\ENDFOR
\ELSE
\FORALL {$ t $ in $ slst $ as $ (P_i, shares_t) $}
\STATE \textbf{send} $ shares_t $
\ENDFOR
\ENDIF
\ENDIF
\end{algorithmic}
\end{multicols}
\end{algorithm}
\end{document}
答案2
将每个元素放在单独的框中是并排显示的另一种方式:
\documentclass{article}
\usepackage[margin=1in]{geometry}% Just for this example
\usepackage{algorithm,algcompatible,lipsum}
\algnewcommand{\lst}{\texttt{lst}}
\algnewcommand{\slst}{\texttt{slst}}
\algnewcommand{\SEND}{\textbf{send}}
\newsavebox{\algleft}
\newsavebox{\algright}
\savebox{\algleft}{%
\begin{minipage}{.49\textwidth}
\begin{algorithm}[H]
\caption{Resolve 1}
\begin{algorithmic}
\scriptsize
\STATE $ P_i $ sends $ id,t_1,t_2,P_j,h_j $ to TTP where $ P_j $ is the party that does not send $ V_j^{(2)} $ to $ P_i $, TTP does the following and sends the returned message to $P_i$:
\IF{$ \mbox{currenttime} > t_1 $}
\STATE \SEND{} msg ``Abort Resolve 1''
\ELSE
\IF { Search($ id, t_1, t_2 $) == NULL }
\STATE \lst{} = Create($ id, t_1, t_2 $)
\STATE \slst{} = Create($ id, t_1, t_2 $)
\STATE \lst.add($ P_i, (P_j,h_j) $)
\STATE \SEND{} msg ``Come after $ t_2 $''
\ELSE
\STATE \lst.add($ P_i, (P_j,h_j $))
\STATE \SEND{} msg ``Come after $ t_2 $''
\ENDIF
\ENDIF
\end{algorithmic}
\end{algorithm}%
\end{minipage}}%
\savebox{\algright}{%
\begin{minipage}{.49\textwidth}
\begin{algorithm}[H]
\caption{Resolve 3}
\begin{algorithmic}
\scriptsize
\STATE $ P_i $ comes either to receive decryption of a $ \{V^{(2)}_t\}_{t \in M} $ where $ M \subseteq N $ or his desired decryption shares from TTP's record.
\STATE $ \mbox{condition} $ = \lst.isEmpty()
\IF {$ \mbox{condition} $ is false }
\STATE \SEND{} msg ``Protocol is aborted''
\ELSE
\IF {$ P_i $ give $\{V^{(2)}_t\}_{t \in M} $}
\FORALL {$ t $ in $ M $}
\STATE \SEND{} Decrypt($ sk, V^{(2)}_t $)
\ENDFOR
\ELSE
\FORALL {$ t $ in $ \slst $ as $ (P_i, \mbox{shares}_t) $}
\STATE \SEND{} $ \mbox{shares}\_t $
\ENDFOR
\ENDIF
\ENDIF
\end{algorithmic}
\end{algorithm}
\end{minipage}}%
\begin{document}
\lipsum[2]
\noindent\usebox{\algleft}\hfill\usebox{\algright}%
\medskip
\lipsum[2]
\end{document}
答案3
一种选择是使用以下multicol
包:
\documentclass[a4paper]{article}
\usepackage{multicol}
\begin{document}
single column text...
\begin{multicols}{2}
algorithm 1
algorithm 2
\end{multicols}
single column text...
\end{document}