1

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" ?

3
  • How did you define \Debut and \Fin? Oct 10, 2012 at 22:09
  • it is werner'algo :\algnewcommand{\Debut}{\Statex \textbf{D\'ebut}\pushindent} \algnewcommand{\Fin}{\Statex \textbf{Fin}\popindent}
    – researcher
    Oct 10, 2012 at 22:10
  • Then define \Donnees in a similar way: \algnewcommand{\Donnees}{\Statex\textbf{Donn\'ees}\pushindent} Oct 10, 2012 at 22:12

1 Answer 1

3

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.

1
  • 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, 2012 at 16:11

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