1

I've already benefited from parbox command to apply some indentation to some lines of my algorithm.

Now, I need to apply indentation to then keyword. As then is automatically generated by \If or ElsIf, I can not use the typical trick of parbox for that.

What I need is depicted in following figure: each then keyword must be aligned w.r.t. its corresponding else if:

enter image description here

My MWE:

\documentclass[letterpaper, 10pt, conference]{IEEEconf}

\let\proof\relax
\let\endproof\relax

\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{mathrsfs}
\usepackage{algorithm}
\usepackage{algorithmicx,algpseudocode}

\newcommand\Sth[1]{S^{#1}\mkern-3mu(\mkern-2.5mu\theta^{\mkern-1mu#1}\mkern-2mu)}

\title{My Title*}

\author{Guy$^{1}$
    \thanks{*This work was not supported by any organization}
    \thanks{$^{1}$Guy is with Hell, {\tt\small guy@hell.edu}}
}

\algnewcommand\algorithmicforeach{\textbf{for each}}
\algdef{S}[FOR]{ForEach}[1]{\algorithmicforeach\ #1\ \algorithmicdo}

\let\oldReturn\Return
\renewcommand{\Return}{\State\oldReturn}

\begin{document}

    \maketitle
    \thispagestyle{empty}
    \pagestyle{empty}

    \begin{abstract}

        ABSTRACT

    \end{abstract}

    \section{INTRODUCTION}

    \begin{algorithm}
        \renewcommand{\thealgorithm}{}
        \caption{algorithm}
        \label{euclid}
        \begin{algorithmic}[1] 
            \While{true}
            \ForEach{xxx}
            \State do $A$
            \If{nothing happened}
            \State \parbox[t]{\dimexpr\linewidth-\algorithmicindent}{$\text{updated var} \gets \varnothing$\strut}
            \ElsIf{objects lie inside the same operating space}
            \ForEach{object with sweeping function $S$}
            \State \parbox[t]{\dimexpr\linewidth-\algorithmicindent}{$\text{updated var} \gets S$\strut}  
            \EndFor
            \ElsIf{objects lie inside different operating space} 
            \ForAll{functions $B$}
            \ForAll{functions $C$}
            \State \parbox[t]{\dimexpr\linewidth-\algorithmicindent}{$\text{updated adjacency} \gets S$\strut}
            \EndFor
            \EndFor
            \EndIf
            \Return updated var
            \EndFor  
            \EndWhile\label{euclidendwhile}
        \end{algorithmic}
    \end{algorithm}
\end{document}

1 Answers1

2
  • There are no line numbers where then is - this is an indicator that this is not an own logical line.
  • It's just a line break because the text is too long in order to fit in one line.
  • I used a very small font size to show you where the logical line breaks occur.
  • You use a documentclass with two columns -- therefore the text width is pretty small.

enter image description here

enter image description here

(I used Show frame/margin in two column layout to show the borders.)

Related Links Regarding the Width of the algorithm Environment

  • 1
    I can't increase the column width, which is something fixed by the conference. On the other hand, decreasing the font size will considerably decrease the readability. I'm wondering whether there is any macro to apply some degrees of freedom to placement of then and its indentation. –  Feb 11 '17 at 21:50