アルゴリズム: 番号付けと配置

アルゴリズム: 番号付けと配置

アルゴリズム的には、「入力」を最初の行に揃えて、表のインデントを減らすにはどうすればよいですか?

\documentclass[a4paper]{scrartcl}
\usepackage{amsmath,amssymb,amsfonts}
\usepackage{algorithm}
\usepackage{algpseudocode}

\algrenewcommand\algorithmicrequire{\textbf{Input:}}
\algrenewcommand\algorithmicensure{\textbf{Output:}}

\begin{document}
    
\begin{algorithm}
    \caption{Anonymous Key Generation}\label{alg:akg}
    \begin{algorithmic}[1]
        \Require \begin{tabular}{l l l}
            $\mathrm{AAA}$ & $=$ & $\mathrm{BBB}$\\
            $\mathrm{CCC}$ & $=$ & $\mathrm{DDD}$
        \end{tabular}
        
        \Ensure $\mathrm{EEE}$
        \State Compute
        \Statex \hspace{\algorithmicindent} 
        \begin{tabular}{l l l}
            $\mathrm{FFF}$ & $\mathrm{=}$ &  $\mathrm{GGG}$\\
            & $\mathrm{=}$ &  $\mathrm{HHH}$ \\
        \end{tabular}
        \State Return $III$
    \end{algorithmic}
\end{algorithm}

\end{document} 

ここに画像の説明を入力してください

答え1

行を揃える必要がある場合は、 の修正バージョンをお勧めします。配置alignedの使用に注意してください。最後の行では を使用しないでください。top\\

\documentclass[a4paper]{scrartcl}
\usepackage{amsmath,amssymb,amsfonts}
\usepackage{algorithm}
\usepackage{algpseudocode}

\algrenewcommand\algorithmicrequire{\textbf{Input:}}
\algrenewcommand\algorithmicensure{\textbf{Output:}}

\newenvironment{ilaligned}{%
  $\openup-1\jot\begin{aligned}[t]%
}{\\[0.5ex]\end{aligned}$}

\begin{document}
    
\begin{algorithm}
    \caption{Anonymous Key Generation}\label{alg:akg}
    \begin{algorithmic}[1]
        \Require \begin{ilaligned}
            \mathrm{AAA} &= \mathrm{BBB}\\
            \mathrm{CCC} &= \mathrm{DDD}
        \end{ilaligned}
        
        \Ensure $\mathrm{EEE}$
        \State Compute
        \Statex \hspace{\algorithmicindent} 
          \begin{ilaligned}
            \mathrm{FFF} &= \mathrm{GGG}\\
                         &= \mathrm{HHH}
          \end{ilaligned}
        \State Return $III$
    \end{algorithmic}
\end{algorithm}

\end{document} 

ここに画像の説明を入力してください

関連情報