Cryptocode/falign:行间距

Cryptocode/falign:行间距

我正在使用加密代码在文档中显示一些与加密相关的内容memoir,但我想减少默认间距,这个间距非常大(特别是在文档其余部分使用一半间距时):

在此处输入图片描述

我设法使所有东西都变小,但仍然遇到一些问题,有时候间距太大(红色方块,有时甚至比原始图片还要大),有时候间距不够(绿色圆圈):

在此处输入图片描述

有什么办法可以修复它吗? 平均能量损失

\documentclass{memoir}

\checkandfixthelayout
%% Configure 1.5 spacing between lines
\OnehalfSpacing
% even if not documented, one must use checkandfixthelayout not to break the title template
% https://tex.stackexchange.com/questions/601273/memoir-checkandfixthelayout-required-for-single-onehalfspacing
\checkandfixthelayout

\usepackage [
lambda,
advantage,
operators,
sets,
adversary,
landau,
probability,
notions,
logic,
ff,
mm,
primitives,
events,
complexity,
asymptotics,
keys
] {cryptocode}
\createprocedureblock{interactGame}{center,boxed}{}{}{}


\begin{document}

What I managed to have (problem: still too much space between two arrows):

\NewExpandableDocumentCommand{\mysendmessageleft}{m}{\sendmessage{<-,inner sep=0pt}{topstyle={inner sep=2pt},top={$#1$}}}
\NewExpandableDocumentCommand{\mysendmessageright}{m}{\sendmessage{->,inner sep=0pt}{topstyle={inner sep=2pt},top={$#1$}}}
\NewDocumentEnvironment{gameInteract}{mb}{
\begin{Spacing}{0}%
  \interactGame[linenumbering]{#1}{#2\vspace{5mm}}
\end{Spacing}\par\vskip\baselineskip % Seems required or the next line will be eated up.
}{}

\begin{gameInteract}{My protocol}
    \textbf{Challenger}                           \>                                      \> \textbf{Adversary} \\
    \> \mysendmessageleft{(m^{(0)},m^{(1)})} \> \text{Compute $m^{(0)}$ and $m^{(1)}$} \\
    c \sample \bin                                  \>                                      \> \\
    (k, t_k) \gets \textsf{Gen}(1^\lambda, m^{(c)}) \>                                      \> \\
    \> \mysendmessageright{k}                \> \\
    \> \mysendmessageleft{\tilde{c}}         \> \\
    \pcreturn \tilde{c} = c                         \>                                      \>
\end{gameInteract}


What I have by default:
{\normalfont \interactGame[linenumbering]{My protocol}{
    \textbf{Challenger}                           \>                                      \> \textbf{Adversary} \\
                                                  \> \sendmessageleft*{(m^{(0)},m^{(1)})} \> \text{Compute $m^{(0)}$ and $m^{(1)}$} \\
  c \sample \bin                                  \>                                      \> \\
  (k, t_k) \gets \textsf{Gen}(1^\lambda, m^{(c)}) \>                                      \> \\
                                                  \> \sendmessageright*{k}                \> \\
                                                  \> \sendmessageleft*{\tilde{c}}         \> \\
  \pcreturn \tilde{c} = c                         \>                                      \>
}}

\end{document}

答案1

的正文排版\gameInteract没有特别注意行距。您可以通过将其设置Spacing为 1.2 并将标签放在箭头上方来获得统一的距离。我还使用 缩小了它们的尺寸\scriptstyle。如果您不喜欢这种风格,请将其删除。

\documentclass{memoir}
\usepackage{amsmath}

\OnehalfSpacing
\checkandfixthelayout

\usepackage [
lambda,
advantage,
operators,
sets,
adversary,
landau,
probability,
notions,
logic,
ff,
mm,
primitives,
events,
complexity,
asymptotics,
keys
] {cryptocode}

\createprocedureblock{interactGame}{center,boxed}{}{}{}

\NewDocumentCommand{\mysendmessageleft}{m}{%
  \sendmessage{<-,inner sep=0pt}{
    topstyle={inner sep=2pt},
    top=\smash[t]{$\scriptstyle#1$},
  }%
}
\NewDocumentCommand{\mysendmessageright}{m}{%
  \sendmessage{->,inner sep=0pt}{
    topstyle={inner sep=2pt},
    top=\smash[t]{$\scriptstyle#1$},
  }%
}

\NewDocumentEnvironment{gameInteract}{m+b}
 {%
  \par\begin{Spacing}{1.2}
  \interactGame[linenumbering]{#1}{#2}
  \par\addvspace{\baselineskip}
  \end{Spacing}
 }{}

\begin{document}

What I managed to have (problem: still too much space between two arrows):

\begin{gameInteract}{My protocol}
  \textbf{Challenger} \> \> \textbf{Adversary} \\
    \> \mysendmessageleft{(m^{(0)},m^{(1)})} \> \text{Compute $m^{(0)}$ and $m^{(1)}$} \\
  c \sample \bin \\
  (k, t_k) \gets \textsf{Gen}(1^\lambda, m^{(c)}) \\
    \> \mysendmessageright{k} \\
    \> \mysendmessageleft{\tilde{c}} \\
  \pcreturn \tilde{c} = c
\end{gameInteract}

Some other text to see what happens after the game.

\end{document}

在此处输入图片描述

答案2

\\您可以使用可选参数向制表环境的相应换行符添加负空格来消除“红框” \\[<vertical space>]

标题行和正文之间的间距由 控制 bodylinesep。我不确定您是否要增加或减少默认值(-3pt在示例中设置为 以显示效果)。

简化环境后,“绿圈”问题消失gameInteract

b

\documentclass{memoir}

\checkandfixthelayout
%% Configure 1.5 spacing between lines
\OnehalfSpacing
% even if not documented, one must use checkandfixthelayout not to break the title template
% https://tex.stackexchange.com/questions/601273/memoir-checkandfixthelayout-required-for-single-onehalfspacing
\checkandfixthelayout

\usepackage [
lambda,
advantage,
operators,
sets,
adversary,
landau,
probability,
notions,
logic,
ff,
mm,
primitives,
events,
complexity,
asymptotics,
keys
] {cryptocode}
\createprocedureblock{interactGame}{center,boxed}{}{}{}

\begin{document}
    
    What I managed to have (problem: still too much space between two arrows):
    
    \NewExpandableDocumentCommand{\mysendmessageleft}{m}{\sendmessage{<-,inner sep=0pt}{topstyle={inner sep=2pt},top={$#1$}}}
    \NewExpandableDocumentCommand{\mysendmessageright}{m}{\sendmessage{->,inner sep=0pt}{topstyle={inner sep=2pt},top={$#1$}}}
    \NewDocumentEnvironment{gameInteract}{mb}{
%       \begin{Spacing}{0}% Not needed
            \interactGame[linenumbering,bodylinesep=-3pt]{#1}{#2}  % changed <<<<<<<<<<<<<<<<<
%       \end{Spacing}\par\vskip\baselineskip % Seems required or the next line will be eated up.
    }{}
    
    \begin{gameInteract}{My new protocol}   
        \textbf{Challenger}                           \>                                      \> \textbf{Adversary} \\
        \> \mysendmessageleft{(m^{(0)},m^{(1)})} \> \text{Compute $m^{(0)}$ and $m^{(1)}$} \\[-1.5ex]% changed <<<<<<<<<<<<<<<<<
        c \sample \bin                                  \>                                      \> \\
        (k, t_k) \gets \textsf{Gen}(1^\lambda, m^{(c)}) \>                                      \> \\
        \> \mysendmessageright{k}                \> \\[-1.5ex]% changed <<<<<<<<<<<<<<<<<
        \> \mysendmessageleft{\tilde{c}}         \> \\
        \pcreturn \tilde{c} = c                         \>                                      \>
    \end{gameInteract}
    
    
    What I have by default:
    {\normalfont \interactGame[linenumbering]{My protocol}{
            \textbf{Challenger}                           \>                                      \> \textbf{Adversary} \\
            \> \sendmessageleft*{(m^{(0)},m^{(1)})} \> \text{Compute $m^{(0)}$ and $m^{(1)}$} \\[-1.5ex]
            c \sample \bin                                  \>                                      \> \\
            (k, t_k) \gets \textsf{Gen}(1^\lambda, m^{(c)}) \>                                      \> \\
            \> \sendmessageright*{k}                \> \\[-2.5ex]
            \> \sendmessageleft*{\tilde{c}}         \> \\
            \pcreturn \tilde{c} = c                         \>                                      \>
    }}
    
    
\end{document}

相关内容