9

How to print

\FOR{$j:=0,\ldots,i-1$} 
         \STATE{$\C_{ij}:=\C_{ii}\cdot\C_{ij}$};
         \ENDFOR

in one line instead of two line?

1

1 Answer 1

7

You should define your own command for placing algorithmic content on a single line. As a suggestion, consider:

\newcommand{\LINEFOR}[2]{%
    \STATE\algorithmicfor\ {#1}\ \algorithmicdo\ {#2} \algorithmicend\ \algorithmicfor%
}

which prints the regular algorithmic package keywords used in the construction of a for statement (\algorithmicfor, \algorithmicdo, etc.), but does all of this in a single \STATE statement (or line).

Here is a complete minimal example illustrating the result:

enter image description here

\documentclass{article}
\usepackage{algorithmic}%
\begin{document}

\newcommand{\LINEFOR}[2]{%
    \STATE\algorithmicfor\ {#1}\ \algorithmicdo\ {#2} \algorithmicend\ \algorithmicfor%
}

\begin{algorithmic}
    \STATE \ldots
    \FOR{$j:=0,\ldots,i-1$}%
        \STATE $\mathcal{C}_{ij}:=\mathcal{C}_{ii}\cdot\mathcal{C}_{ij}$;%
        \ENDFOR%
    \STATE \ldots
    \LINEFOR{$j:=0,\ldots,i-1$}{$\mathcal{C}_{ij}:=\mathcal{C}_{ii}\cdot\mathcal{C}_{ij}$}%
    \STATE \ldots
\end{algorithmic}

\end{document}
1
  • A version that makes an if one one line: newcommand{\LineIf}[2]{ \State \algorithmicif\ {#1}\ \algorithmicthen\ {#2} \algorithmicend\ \algorithmicif }
    – dtech
    Commented Sep 18, 2013 at 15:19

You must log in to answer this question.

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