\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{cryptocode}
\usepackage{dashbox}
\begin{document}
\begin{figure}[h]
\centering
\fbox{%
\pseudocode[]{%
\textsc{\large Left} \<\< \textsc{\large Right} \\[][\hline]
\<\< \\[-0.5\baselineskip]
\begin{subprocedure}%
\dbox{\procedure{\textsc{Short}}{%
\text{command} \\
\text{command}
}}
\end{subprocedure}\\[-1.5\baselineskip]
\< \sendmessageright*{(x,y)} \<
\<\<\begin{subprocedure}%
\dbox{\procedure{\textsc{Long }}{%
\text{command loooooong}\\
\text{command loooooong}
}}
\end{subprocedure}\\[-1.5\baselineskip]
\< \sendmessageleft*{(a,b)} \<
\<\< \\[-1.5\baselineskip]
\begin{subprocedure}%
\dbox{\procedure{\textsc{Middle }}{%
\text{command longer}\\
\text{command longer}
}}
\end{subprocedure}
}
}
\end{figure}
\end{document}
如何实现函数“LONG”与右列开头对齐?换句话说,我想删除“LONG”和箭头之间的空白...
另外,是否可以将“SHORT”对齐到箭头旁边的右侧?这样空白就会位于其左侧?
谢谢你的帮助,我找不到有效的解决方案
答案1
对于第一个问题,你只是对列数有误。至于第二个问题,由于第一列是左对齐的,你可以\hspace{some length}
在程序前面添加一个。长度必须通过反复试验才能找到。以下是可能性:
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{cryptocode}
\usepackage{dashbox}
\begin{document}
\begin{figure}[h]
\centering
\fbox{%
\pseudocode[]{%
\textsc{\large Left} \<\< \textsc{\large Right} \\[][\hline]
\<\< \\[-0.5\baselineskip]
\hspace{2.75em} \begin{subprocedure}%
\dbox{\procedure{\textsc{Short}}{%
\text{command} \\
\text{command}
}}
\end{subprocedure}\\[-1.5\baselineskip]
\< \sendmessageright*{(x,y)} \<
%\< \< delet these column changes
\begin{subprocedure}%
\dbox{\procedure{\textsc{Long }}{%
\text{command loooooong}\\
\text{command loooooong}
}}
\end{subprocedure}\\[-1.5\baselineskip]
\< \sendmessageleft*{(a,b)} \<
\<\< \\[-1.5\baselineskip]
\begin{subprocedure}%
\dbox{\procedure{\textsc{Middle }}{%
\text{command longer}\\
\text{command longer}
}}
\end{subprocedure}
}
}
\end{figure}
\end{document}
答案2
在\pseudocode
列对中创建列;在每对中,第一列左对齐,第二列右对齐。因此你需要
l1 r1 l2 r2 l3
因此“SHORT”和“MIDDLE”应该放在列中r1
,“LONG”应该放在列中l3
。
如何处理“Left”标签?将其放在列中l1
,宽度为零。
命令\>
是“转到下一列”;\<
是“转到下一列之后的列”。
\documentclass{article}
\usepackage{cryptocode}
\usepackage{dashbox}
\begin{document}
\begin{figure}[htp]
\centering
\fbox{%
\pseudocode[]{%
\makebox[0pt][l]{\textsc{\large Left}} \<\< \textsc{\large Right} \\[][\hline]
\mbox{} \\[-0.5\baselineskip]
\> \begin{subprocedure}%
\dbox{\procedure{\textsc{Short}}{%
\text{command} \\
\text{command}
}}
\end{subprocedure}\\[-1.5\baselineskip]
\< \sendmessageright*{(x,y)} \<
\begin{subprocedure}%
\dbox{\procedure{\textsc{Long }}{%
\text{command loooooong}\\
\text{command loooooong}
}}
\end{subprocedure}\\[-1.5\baselineskip]
\< \sendmessageleft*{(a,b)}
\\[-1.5\baselineskip]
\> \begin{subprocedure}%
\dbox{\procedure{\textsc{Middle }}{%
\text{command longer}\\
\text{command longer}
}}
\end{subprocedure}
}
}
\end{figure}
\end{document}