6

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)?

1
  • 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 at 14:28
6

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}

Not the answer you're looking for? Browse other questions tagged or ask your own question.