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.

This is a follow-up question to Option in the algorithm with Latex. This is my algorithm:

 \usepackage{algorithm}
 \usepackage{algorithmic}
 \begin{document}
 \begin{algorithm}[H]
 \caption{My algo}
 \begin{algorithmic}[1]
 \Debut
 \LState instruction 1
 \LState instruction 2
  \Fin
 \end{algorithmic}
 \end{algorithm}
 \end{document}

enter image description here

Please how can I add "Données" before "Début" ?

share|improve this question

closed as too localized by Stephan Lehmke, Gonzalo Medina, Thorsten, Stefan Kottwitz Oct 11 '12 at 6:01

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.If this question can be reworded to fit the rules in the help center, please edit the question.

    
How did you define \Debut and \Fin? –  Gonzalo Medina Oct 10 '12 at 22:09
    
it is werner'algo :\algnewcommand{\Debut}{\Statex \textbf{D\'ebut}\pushindent} \algnewcommand{\Fin}{\Statex \textbf{Fin}\popindent} –  researcher Oct 10 '12 at 22:10
    
Then define \Donnees in a similar way: \algnewcommand{\Donnees}{\Statex\textbf{Donn\'ees}\pushindent} –  Gonzalo Medina Oct 10 '12 at 22:12
    
thank you Gonzalo :) –  researcher Oct 10 '12 at 22:27
add comment

1 Answer 1

up vote 3 down vote accepted

Adding

\algnewcommand{\Donnees}{\Statex \textbf{Donn\'ees}}

you can now obtain

enter image description here

\begin{algorithm}
  \caption{My algorithme}
  \begin{algorithmic}[1]
    \Donnees: My data
    \Statex% Blank line
    \Debut
      \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$
      \EndWhile\label{euclidendwhile}
      \LState \textbf{Retour} $b$\Comment{The gcd is b}
    \Fin
  \end{algorithmic}
\end{algorithm}
\end{document}

The use of \Statex inserts a blank line, depending on whether you need a separation between the algorithm and the input.

The above code snippet uses the same preamble as in Option in the algorithm with LaTeX.

share|improve this answer
    
Please i have one more question: when i divide the algorithm after an IF and before an EndIF, i have an error , have you an idea please? –  researcher Dec 11 '12 at 16:11
add comment

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