6

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

2 Answers 2

8

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}
1
  • Thanks so much for this simple solution!!!
    – aysljc
    Commented Feb 1, 2023 at 23:52
7

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}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .