# Align Input and Output of algorithm to left

I use the following template for KDD 2017 - for conference (sample-sigconf file): here. This is the code I use for the my algorithm:

\documentclass[sigconf]{acmart}
\usepackage{booktabs,makecell,tabularx}

\newcolumntype{L}{>{\raggedright\arraybackslash}X}
\usepackage{siunitx}
\usepackage{array,booktabs}

\usepackage{graphicx}
\usepackage{epstopdf}

%\newcolumntype{C}[1]{>{\centering\arraybackslash}p{#1}}
\usepackage{algorithm}% http://ctan.org/pkg/algorithms
\usepackage{algpseudocode}% http://ctan.org/pkg/algorithmicx
\usepackage{amsmath}

\begin{algorithm} [H]
\caption{Dsfdgfgskj sdfgfkjsdl sdfggjlkj fgsdt}
\label{alg:ALG1}
\textbf{INPUT:} $x$ - decision tree\\
\textbf{OUTPUT:} $abc$ is $x$ in Txx Bxxxxx Gxxxx
\begin{algorithmic}
\State  Function $UpdateNodes(x)$:

\If {  $wrejkwe$ ($rw$) trwer tewwerl }
%       \COMMENT {
\State {jklrjkljfgkljlkj  kjkldfj gfdsdf }
\State  Set fdgsdsd
\ForAll  {$j=1$ to $N (x)$}
\State        Call fgsd(x)\State Set sfgdfgd =sfdg + fgds \EndFor \EndIf \end{algorithmic} \end{algorithm}  However, the input and output are aligned to center. How can I change it to be aligned to left? ## 2 Answers Adding \begin{flushleft} solves the problem: \begin{algorithm} [H] \caption{Dsfdgfgskj sdfgfkjsdl sdfggjlkj fgsdt} \label{alg:ALG1} \begin{flushleft} \textbf{INPUT:}x$- decision tree\\ \textbf{OUTPUT:}$abc$is$x$in Txx Bxxxxx Gxxxx \end{flushleft} \begin{algorithmic} \State Function$UpdateNodes(x)$: \If {$wrejkwe$($rw$) trwer tewwerl } % \COMMENT { \State {jklrjkljfgkljlkj kjkldfj gfdsdf } \State Set fdgsdsd \ForAll {$j=1$to$N (x)$} \State Call fgsd(x)$
\State        Set sfgdfgd =sfdg + fgds

\EndFor
\EndIf

\end{algorithmic}
\end{algorithm}

• Thanks so much for this simple solution!!! Commented Feb 1, 2023 at 23:52

Use the commands of package algpseudocode to define input, output, and function heading. The predefined commands \Require and \Ensure are intended for describing the in- and output. If you don't like the keywords Require and Ensure, redefine them:

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


You can also define new statements \Input and \Output:

\algnewcommand\algorithmicinput{\textbf{Input:}}
\algnewcommand\algorithmicoutput{\textbf{Output:}}
\algnewcommand\Input{\item[\algorithmicinput]}%
\algnewcommand\Output{\item[\algorithmicoutput]}%


Now you can use \Input ...description of input and likewise \Output ....

 \Function {UpdateNodes}{$x$}
...
\EndFunction


\documentclass[sigconf]{acmart}
\usepackage{algorithm}% http://ctan.org/pkg/algorithms
\usepackage{algpseudocode}% http://ctan.org/pkg/algorithmicx
\algrenewcommand\algorithmicrequire{\textbf{Input:}}
\algrenewcommand\algorithmicensure{\textbf{Output:}}
\begin{document}
\begin{algorithm}
\caption{Dsfdgfgskj sdfgfkjsdl sdfggjlkj fgsdt}
\label{alg:ALG1}
\begin{algorithmic}
\Require $x$ - decision tree
\Ensure $abc$ is $x$ in Txx Bxxxxx Gxxxx
\Function {UpdateNodes}{$x$}
\If {  $wrejkwe$ ($rw$) trwer tewwerl }
%       \COMMENT {
\State {jklrjkljfgkljlkj  kjkldfj gfdsdf }
\State  Set fdgsdsd
\ForAll  {$j=1$ to $N (x)$}
\State        Call $fgsd(x)$
\State        Set $sfgdfgd =sfdg + fgds$

\EndFor
\EndIf
\EndFunction
\end{algorithmic}
\end{algorithm}
\end{document}