TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

This is my algorithm:

 \caption{My algo}
 \STATE instruction 1
 \STATE instruction 2

Please, i ask how can i specify which instruction have applied this option: 1 ? enter image description here

i'd like to delete the number before "Début" and befor "Fin", i'd like also add spacing before "ch" and "po"

share|improve this question
The option [1] says number everyline. Changing it to [2] places line numbers on lines 2,4,6,... etc. – Andrew Swann Oct 6 '12 at 13:51
up vote 3 down vote accepted

The optional argument to algorithmic ([1] in this case), provides the line numbered at every line. A numbering modulo 2 would be obtained using [2], and so forth.

Here's a slight variation of Is it possible to have connecting loop lines (like algorithm2e) in algorithmic? - using algpseudocode (from algorithmicx) - to insert Début and Fin as keywords. Others still need to be translated to French:

enter image description here

\usepackage{algorithm}% http://ctan.org/pkg/algorithm
\usepackage{algpseudocode}% http://ctan.org/pkg/algorithmicx

\renewcommand{\ALG@name}{Algorithme}% Algorithm in French
\algnewcommand{\Debut}{\Statex \textbf{D\'ebut}\pushindent}
\algnewcommand{\Fin}{\Statex \textbf{Fin}\popindent}

% This is the vertical rule that is inserted
\def\therule{\makebox[\algorithmicindent][l]{\hspace*{.5em}\vrule height .75\baselineskip depth .25\baselineskip}}%

\newtoks\therules% Contains rules
\therules={}% Start with empty token list
\def\appendto#1#2{\expandafter#1\expandafter{\the#1#2}}% Append to token list
\def\gobblefirst#1{% Remove (first) from token list
\def\LState{\State\unskip\the\therules}% New line-state

%      ***      DECLARED LOOPS      ***
% (from algpseudocode.sty)
  {\printandpush\textbf{Tant que} #1}
  {\popandprint\textbf{Fin Tant que}}%
  {\printandpush\algorithmicfor\ #1\ \algorithmicdo}
  {\popandprint\algorithmicend\ \algorithmicfor}%
  {\printindent\algorithmicforall\ #1\ \algorithmicdo}%
  {\popandprint\algorithmicend\ \algorithmicloop}%
  {\popandprint\algorithmicuntil\ #1}%
  {\printandpush\algorithmicif\ #1\ \algorithmicthen}
  {\popandprint\algorithmicend\ \algorithmicif}%
  {\popandprint\pushindent\algorithmicelse\ \algorithmicif\ #1\ \algorithmicthen}%
   {\printandpush\algorithmicprocedure\ \textproc{#1}\ifthenelse{\equal{#2}{}}{}{(#2)}}%
   {\popandprint\algorithmicend\ \algorithmicprocedure}%
   {\printandpush\algorithmicfunction\ \textproc{#1}\ifthenelse{\equal{#2}{}}{}{(#2)}}%
   {\popandprint\algorithmicend\ \algorithmicfunction}%


  \caption{My algorithme}
      \LState $r\gets a\bmod b$
      \While{$r\not=0$}\Comment{We have the answer if r is 0}
        \LState $a\gets b$
        \LState $b\gets r$
        \LState $r\gets a\bmod b$
      \LState \textbf{Retour} $b$\Comment{The gcd is b}

\State provides a "regular line" (with number), while \Statex provides an unnumbered line. As such, I've defined both Début and Fin to be of \Statex.

Adding the macro

\def\LStatex{\Statex\unskip\the\therules}% New line-state

allows you to print an unnumbered line. Now you can use it as follows:

enter image description here

  \caption{My algorithme}
      \LState $r\gets a\bmod b$
      \While{$r\not=0$}\Comment{We have the answer if r is 0}
        \LState $a\gets b$
        \LState Here is a very long expression
        \LStatex \expandafter\hskip\algorithmicindent\relax that has to go to a new line.
        \LState $r\gets a\bmod b$
      \LState \textbf{Retour} $b$\Comment{The gcd is b}
share|improve this answer
Thank you for help,i'd like also add spacing before "ch" and "po" have you an idea please? – researcher Oct 6 '12 at 15:08
@researcher: Are you referring to vertical or horizontal spacing? – Werner Oct 6 '12 at 16:50
horizontal spacing – researcher Oct 6 '12 at 16:55
@researcher: I assume it's for just the single line? Alternatively, one can increase the entire algorithm indent... – Werner Oct 6 '12 at 17:05
in my algorithme i have a long instruction. "ch" is its end , how can i add spacing before "ch" – researcher Oct 6 '12 at 17:11

Your Answer


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.