Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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?

share|improve this question
    
Welcome to TeX.sx! Please always add a full, but minimal working example (MWE) that illustrates your problem. –  Martin Scharrer Jul 11 '11 at 15:20
add comment

1 Answer 1

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}
share|improve this answer
    
Thank you very much –  Mohammad Jul 12 '11 at 14:47
    
A version that makes an if one one line: newcommand{\LineIf}[2]{ \State \algorithmicif\ {#1}\ \algorithmicthen\ {#2} \algorithmicend\ \algorithmicif } –  dtech Sep 18 '13 at 15:19
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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