我该如何改变对齐方式?

我该如何改变对齐方式?

你好,我想问一下如何使用这个algorithm包。代码如下:

\documentclass[sigconf]{acmart}
\usepackage{booktabs} % For formal tables
\usepackage{algorithm}
\usepackage{algorithmic}
\usepackage{tabularx}
\begin{document}
\begin{algorithm}[H]
\floatname{algorithm}{Algorithm}
\renewcommand{\thealgorithm}{}
\caption{De}
\label{alg:demixng}
for i= 1 to N.
\begin{algorithmic}[1]
\STATE $M$ : Eavesdrops the protocol 1 above and gets $X$ from step 1 and initiates the same protocol with $B$, by substituting $X$ for $K$ above.
\STATE $M\rightarrow{B}$ : $P = E_{B}(S_{M}(X)) = E_{B}(S_{M}(E_{B}(S_{A}(K))))$
\STATE $B$ : $V_{M}(D_{B}(P)) = V_{A}(D_{B}(E_{B}(S_{A}(X)))) = X$
\STATE $B\rightarrow{M}$ : $Q = E_{M}(S_{B}(X)) = E_{M}(S_{B}(E_{B}(S_{A}(K))))$\\
Since the same key pair is used for both encryption and signing, $S_{B}(E_{B}(message)) = message$\\
Therefore, $Q = E_{M}(S_{A}(K))$
\STATE $M$ : $D_{M}(Q) = S_{A}(K)$
\STATE $M$ : Since the same key pair is used for both encryption and signing, $E_{A}(S_{A}(K)) = K$. Mallory can obtain the key $K$ in this way and decrypt all the subsequent messages encrypted with key $K$.
\end{algorithmic}
\end{algorithm} 
\end{document}

结果如下:

结果屏幕

我想要两件事:

  1. 我想从左边的第一句话开始。
  2. 我想把数字改为中间的4a,4b。

我只是将想要的结果绘制成 Paint。

在此处输入图片描述

我对 LaTeX 还不是很熟悉,如果能得到您的帮助我将不胜感激。

答案1

对于对齐:只需\hfill在线后面插入一个。

对于另一部分问题,我定义了一个名为的环境sublines@algoritmic

\documentclass[sigconf]{acmart}
\usepackage{lmodern}
\usepackage{booktabs} % For formal tables
\usepackage{algorithm}
\usepackage{algorithmic}
\usepackage{tabularx}
\makeatletter
\newenvironment*{sublines@algorithmic}
{%
  \stepcounter{ALC@line}%
  \edef\tmp@sublines{\theALC@line}%
  \setcounter{ALC@line}{0}%
  \renewcommand{\ALC@lno}{%
    {\ALC@linenosize\tmp@sublines\alph{ALC@line}\ALC@linenodelimiter}}%
}{%
  \setcounter{ALC@line}{\tmp@sublines}%
}
\makeatother
\begin{document}
\begin{algorithm}[H]
\floatname{algorithm}{Algorithm}
\renewcommand{\thealgorithm}{}
\caption{De}
\label{alg:demixng}
for i= 1 to N.\hfill
\begin{algorithmic}[1]
\STATE $M$ : Eavesdrops the protocol 1 above and gets $X$ from step 1 and initiates the same protocol with $B$, by substituting $X$ for $K$ above.
\STATE $M\rightarrow{B}$ : $P = E_{B}(S_{M}(X)) = E_{B}(S_{M}(E_{B}(S_{A}(K))))$
\STATE $B$ : $V_{M}(D_{B}(P)) = V_{A}(D_{B}(E_{B}(S_{A}(X)))) = X$
\begin{sublines@algorithmic}
\STATE $B\rightarrow{M}$ : $Q = E_{M}(S_{B}(X)) = E_{M}(S_{B}(E_{B}(S_{A}(K))))$\\
Since the same key pair is used for both encryption and signing, $S_{B}(E_{B}(message)) = message$\\
Therefore, $Q = E_{M}(S_{A}(K))$
\STATE $M$ : $D_{M}(Q) = S_{A}(K)$
\end{sublines@algorithmic}
\STATE $M$ : Since the same key pair is used for both encryption and signing, $E_{A}(S_{A}(K)) = K$. Mallory can obtain the key $K$ in this way and decrypt all the subsequent messages encrypted with key $K$.
\end{algorithmic}
\end{algorithm} 
\end{document}

在此处输入图片描述

相关内容