7

In latex, I am writing a pseudocode where I want to have output (of input and output) in the following fashion: enter image description here

This is my code:

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

And this is my output:My output

When I use \Input{..} or \Output{..} in my code, I get the following error:

! Undefined control sequence.<recently read> \Input \Input  
! Undefined control sequence \Output

How can I get the desired output (the first picture)?

Commoner
  • 173
  • 1
  • 1
  • 4
  • Don't think this is a duplicate question because this one is implicitly asking how to align the text for multiple inputs – Vivek Jul 26 '21 at 14:28

1 Answers1

8

It is easiest to produce output where the "Input" and "Output" headings are on lines of their own, which may be good enough for your purposes:

Sample output

\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}
Andrew Swann
  • 95,762
  • Is there a way to make the \Desc command add correct amount of white-space if the description text is longer then what fits on the first row? – Baraliuh Jan 07 '22 at 21:20
  • 1
    @Baraliuh You could replace the #2 in the definition of \Desc by something like \parbox[t]{some width}{#2}. – Andrew Swann Jan 08 '22 at 11:11