[Tex/LaTex] Align Input and Output of algorithm to left

algorithmicalgorithmsalign

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}

\renewcommand\theadfont{\small}
\newcolumntype{L}{>{\raggedright\arraybackslash}X}
\usepackage{siunitx}
\usepackage{adjustbox}
\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?
enter image description here

Best Answer

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 ....

For the function heading, use

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

enter image description here

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