알고리즘: 번호 매기기 및 정렬

알고리즘: 번호 매기기 및 정렬

알고리즘에서 "입력"을 첫 번째 줄에 정렬하고 테이블의 들여쓰기를 줄이려면 어떻게 해야 합니까?

\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. \\마지막 행에는 No를 사용해야 합니다.

\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} 

여기에 이미지 설명을 입력하세요

관련 정보