3

I am using algorithm2e package to write an algorithm. I need to define functions where their descriptions are multi-lines. In the first function only, algorithm2e adds extra space in the second, third, ..etc. line. But from the second function and afterwards, it does not add this extra space which looks as I want. I need to remove the extra space added in the first function lines (all lines after the first line). The script is here. I use ACM conference template and I need the algorithm in 2 columns as it is long (not like this small sample).

Here is the script:

\documentclass[sigconf]{acmart}
\pagestyle{empty}
\usepackage{amsmath}
\usepackage[ruled,vlined]{algorithm2e} 
\usepackage{multicol} 

\begin{document}
\title{Title Here}

\begin{abstract}
Abstract here.
\end{abstract}

\maketitle

\section{Algorithm}
\begin{algorithm*}
\begin{multicols}{2}
    \SetKwInOut{Input}{input}\SetKwInOut{Output}{output}\SetKwInOut{Functions}{Functions}
    \SetKwFunction{Query}{Query}\SetKwFunction{Calc}{Calc}


    \Functions
    {
        \Query{$a,b$}: Queries a and b and returns the answer as c. This function name is Query.\;
        \Calc{$a,b$}: Calculates a and b and returns the answer as c. This function name is Calc.\;
    }


\caption{The algorithm}
\label{alg:query-verify}
\end{multicols}
\end{algorithm*}

\end{document}

Here is the figure: enter image description here

2

This solution is adapted from https://tex.stackexchange.com/a/335862/90297:

Basically renew the \SetKWInOut command so that the indent size would be 0em.

\documentclass[sigconf]{acmart}
\pagestyle{empty}
\usepackage{amsmath}
\usepackage[ruled,vlined]{algorithm2e} 
\usepackage{multicol} 

\makeatletter
\renewcommand{\SetKwInOut}[2]{%
  \sbox\algocf@inoutbox{\KwSty{#2\algocf@typo:}}%
  \expandafter\ifx\csname InOutSizeDefined\endcsname\relax% if first time used
    \newcommand\InOutSizeDefined{}\setlength{\inoutsize}{\wd\algocf@inoutbox}%
    \sbox\algocf@inoutbox{\parbox[t]{\inoutsize}{\KwSty{#2\algocf@typo\hfill:}}~}\setlength{\inoutindent}{0em}%{\wd\algocf@inoutbox}% <------------
  \else% else keep the larger dimension
    \ifdim\wd\algocf@inoutbox>\inoutsize%
    \setlength{\inoutsize}{\wd\algocf@inoutbox}%
    \sbox\algocf@inoutbox{\parbox[t]{\inoutsize}{\KwSty{#2\algocf@typo\hfill:}}~}\setlength{\inoutindent}{0em}%{\wd\algocf@inoutbox}% <------------------
    \fi%
  \fi% the dimension of the box is now defined.
  \algocf@newcommand{#1}[1]{%
    \ifthenelse{\boolean{algocf@hanginginout}}{\relax}{\algocf@seteveryparhanging{\relax}}%
    \ifthenelse{\boolean{algocf@inoutnumbered}}{\relax}{\algocf@seteveryparnl{\relax}}%
    {\let\\\algocf@newinout\hangindent=\inoutindent\hangafter=1\parbox[t]{\inoutsize}{\KwSty{#2\algocf@typo\hfill:}}~##1\par}
    \algocf@linesnumbered% reset the numbering of the lines
    \ifthenelse{\boolean{algocf@hanginginout}}{\relax}{\algocf@reseteveryparhanging}%
  }}%
\makeatother

\begin{document}
\title{Title Here}

\begin{abstract}
Abstract here.
\end{abstract}

\maketitle
\section{Algorithm}
\begin{algorithm*}
\begin{multicols}{2}
    \SetKwInOut{Input}{input}\SetKwInOut{Output}{output}\SetKwInOut{Functions}{Functions}
    \SetKwFunction{Query}{Query}\SetKwFunction{Calc}{Calc}



    \Functions
    {
        \Query{$a,b$}: Queries a and b and returns the answer as c. This function name is Query.\;
        \Calc{$a,b$}: Calculates a and b and returns the answer as c. This function name is Calc.\;
    }



\caption{The algorithm}
\label{alg:query-verify}
\end{multicols}
\end{algorithm*}

\end{document}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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