![latex算法中的输入和输出](https://linux22.com/image/368002/latex%E7%AE%97%E6%B3%95%E4%B8%AD%E7%9A%84%E8%BE%93%E5%85%A5%E5%92%8C%E8%BE%93%E5%87%BA.png)
在 Latex 中,我正在编写一个伪代码,我希望以以下方式输出(输入和输出):
这是我的代码:
\documentclass[sigconf]{acmart}
\usepackage{amsmath}
\usepackage{algorithm}
\usepackage{algpseudocode}
\begin{document}
\begin{algorithm}\label{algo:ProclivityProp2}
\caption{Graph}
\begin{algorithmic}
\State Input T matrix of measurements
\State Output $\hat X$ \quad matrix of graph signals\\
$\hat W$ \quad matrix of outliers\\
\end{algorithmic}
\end{algorithm}
\end{document}
当我在代码中使用 \Input{..} 或 \Output{..} 时,出现以下错误:
! Undefined control sequence.<recently read> \Input \Input
! Undefined control sequence \Output
我怎样才能获得所需的输出(第一张图片)?
答案1
最简单的方法是生成输出,其中“输入”和“输出”标题位于它们自己的行上,这可能足以满足您的目的:
\documentclass[sigconf]{acmart}
\usepackage{amsmath}
\usepackage{algorithm}
\usepackage{algpseudocode}
\algblock{Input}{EndInput}
\algnotext{EndInput}
\algblock{Output}{EndOutput}
\algnotext{EndOutput}
\newcommand{\Desc}[2]{\State \makebox[2em][l]{#1}#2}
\begin{document}
\begin{algorithm}\label{algo:ProclivityProp2}
\caption{Graph}
\begin{algorithmic}
\Input
\Desc{T}{matrix of measurements}
\EndInput
\Output
\Desc{$\hat X$}{matrix of graph signals}
\Desc{$\hat W$}{matrix of outliers}
\EndOutput
\end{algorithmic}
\end{algorithm}
\end{document}