2

The ifaccong.cls is located here https://www.ifac-control.org/events/resolveuid/b0e4734736878819db179d76290a8f78. How do I do algorithms in the ifacconf document class? Using algorithm2e package causes problems " /usr/local/texlive/2020/texmf-dist/tex/latex/algorithm2e/algorithm2e.sty, line 2746 LaTeX Error: Command \algorithm already defined"

but omitting it doesn't let me use \State \While etc

    \documentclass{ifacconf}

\usepackage{lineno}
\modulolinenumbers[5]
\usepackage{graphicx} 
\usepackage[font=small,labelfont=bf]{caption}
\usepackage{subcaption}

\usepackage{natbib}
\usepackage{algorithm}% <=================http://ctan.org/pkg/algorithms
\usepackage{algpseudocode}% <========== http://ctan.org/pkg/algorithmicx
\usepackage{hyperref} % <===============================================
%\usepackage[ruled,vlined]{algorithm2e}

\begin{document}

\begin{algorithm}[H]
\SetAlgoLined
\KwResult{Write here the result }
 initialization\;
 \While{While condition}{
  instructions\;
  \eIf{condition}{
   instructions1\;
   instructions2\;
   }{
   instructions3\;
  }
 }
 \caption{How to write algorithms}
\end{algorithm}



\end{document}

1 Answer 1

1

You're using a syntax from algorithm2e that doesn't provide \State. So, drop

\usepackage{algorithm}
\usepackage{algpseudocode}

and just use

\usepackage[ruled,vlined,algo2e]{algorithm2e}

together with setting your algorithm inside an algorithm2e environment, not an algorithm environment:

enter image description here

\documentclass{ifacconf}

\usepackage{natbib}
\usepackage[ruled,vlined,algo2e]{algorithm2e}

\begin{document}

\begin{algorithm2e}
  \SetAlgoLined
  \KwResult{Write here the result }
  initialization\;
  \While{While condition}{
    instructions\;
    \eIf{condition}{
      instructions1\;
      instructions2\;
    }{
      instructions3\;
    }
  }
  \caption{How to write algorithms}
\end{algorithm2e}

\end{document}

Also note that I've dropped the [H]ere float placement specifier as you're working within a two-column document.

You must log in to answer this question.

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