1

I have a problem displaying a comment, I would like the comment to be displayed at the right of "then" in the second and the third if statements and here is what I obtain instead.

enter image description here

    \documentclass[sigconf,review]{acmart}
\usepackage{algorithmic}
\usepackage{fixltx2e}
\usepackage{algorithm}
\usepackage{enumitem}
\usepackage{booktabs, makecell, multirow, tabularx}
\newcommand{\mh}[1]{
  {\color{green!70!black} MH: #1}}
 \newcommand{\cmd}[1]{
  {\color{blue} CMD: #1}} 
  \newcommand{\rev}[1]{
  {\color{purple} REV: #1}} 

\newcommand\mytab[1]{\begin{tabular}[t]{@{}c@{}} #1 \end{tabular}}
\newcommand\mc[2]{\multicolumn{#1}{c}{#2}}
 \renewcommand{\algorithmiccomment}[1]{//#1}
%%
%% \BibTeX command to typeset BibTeX logo in the docs


%% Rights management information.  This information is sent to you
%% when you complete the rights form.  These commands have SAMPLE
%% values in them; it is your responsibility as an author to replace
%% the commands and values with those provided to you when you
%% complete the rights form.
%\setcopyright{acmcopyright}
%\copyrightyear{2018}
%\acmYear{2018}
%\acmDOI{10.1145/1122445.1122456}
%
%%% These commands are for a PROCEEDINGS abstract or paper.
%\acmConference[Woodstock '18]{Woodstock '18: ACM Symposium on Neural
%  Gaze Detection}{June 03--05, 2018}{Woodstock, NY}
%\acmBooktitle{Woodstock '18: ACM Symposium on Neural Gaze Detection,
%  June 03--05, 2018, Woodstock, NY}
%\acmPrice{15.00}
%\acmISBN{978-1-4503-9999-9/18/06}


%%
%% Submission ID.
%% Use this when submitting an article to a sponsored event. You'll
%% receive a unique submission ID from the organizers
%% of the event, and this ID should be used as the parameter to this command.
%%\acmSubmissionID{123-A56-BU3}

%%
%% The majority of ACM publications use numbered citations and
%% references.  The command \citestyle{authoryear} switches to the
%% "author year" style.
%%
%% If you are preparing content for an event
%% sponsored by ACM SIGGRAPH, you must use the "author year" style of
%% citations and references.
%% Uncommenting
%% the next command will enable that style.
%%\citestyle{acmauthoryear}

%%
\usepackage{titlesec}
\titlespacing{\subsection}{0pc}{0.5pc}{0pc}
\titlespacing{\subsubsection}{0pc}{0pc}{0pc}

\begin{document}  

\begin{algorithm}
\caption{Step 4-T Propagation}

\begin{algorithmic}[1]

    \raggedright



    \STATE \textbf{do}
    \FORALL{r in requirements}   
    \FORALL{m in methods}   
        \IF {rtm[m,r]==U}
    \IF {
        m.callees.isEmpty() \hfill\COMMENT{\textit{Leaf}}
        \newline
        \AND atLeast1T(rtm[m.callers,r])
    }
    \STATE rtm[m,r]=T

    \ELSIF {allTs(rtm[m.callers,r]))\hfill\COMMENT{\textit{Default}}}

    \STATE rtm[m,r]=T 
    \ELSIF {allTs(rtm[m.callees,r]))\hfill\COMMENT{\textit{Default}}}

    \STATE rtm[m,r]=T 
    \ENDIF 
\ENDIF 
    \ENDFOR 
    \ENDFOR 
    \STATE ~\textbf{until no more predictions are made}
\end{algorithmic}
\label{step4}
\end{algorithm}


\end{document}
1

algorithmic's \ELSIF[<comment>]{<condition>} takes two arguments, the first of which is optional. Below I've updated \algorithmiccomment to match your proposed style, and also used a \REPEAT...\UNTIL{<condition>} clause that simulates your verbatim do...until clause. The former provides the proper indentation while yours does not.

enter image description here

\documentclass[sigconf,review]{acmart}

\usepackage{algorithm,algorithmic}
\renewcommand{\algorithmiccomment}[1]{\hfill // \textit{#1}}

\newcommand{\rtm}[1][m,r]{\text{rtm\textsubscript{m}[\text{#1}]}}

\begin{document}

\begin{algorithm}
  \caption{Step 4-T Propagation}
  \begin{algorithmic}[1]
    \raggedright
    \REPEAT
      \FORALL{r in requirements}
        \FORALL{m in methods}
          \IF{$\rtm = U$}
            \IF{
              (m.callees.isEmpty() \COMMENT{Leaf}
              \newline
              \AND atLeast1T(\rtm[m.callers,r]))
            }
              \STATE $\rtm = T$
            \ELSIF[First comment]{allTs(\rtm[m.callers,r]))}
              \STATE $\rtm = T$
            \ELSIF[Second comment]{allTs(\rtm[m.callees,r]))}
              \STATE $\rtm = T$
            \ENDIF
          \ENDIF
        \ENDFOR
      \ENDFOR
    \UNTIL{no more predictions are made}
  \end{algorithmic}
\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.