26

I want to draw vertical line by using \SetAlgoLined, but LaTeX told me Undefined control sequence.

Then I add \usepackage{algorithm2e} to the end of my preamble. Then it said Command\algorithmalready defined.

\usepackage{graphicx}  
\usepackage{xthesis}  
\usepackage{xtocinc}  
\usepackage{mystyle}  
\usepackage{url}  
\usepackage{subfigure}  
\usepackage{booktabs}  
\usepackage{multirow}  
\usepackage[printonlyused]{acronym}  
\usepackage{algorithm} 
\usepackage{algorithmic}  
\usepackage{float}  
\usepackage{epstopdf}  
\usepackage{amssymb,amsmath}  
\usepackage{graphicx,epsfig}  
\usepackage{multicol}  
\usepackage{ifthen}  
\usepackage{algorithm2e}  

I'm using Window 7 + TexWorks. I have another paper works perfect with algorithm2e and \SetAlgoLined:

\usepackage{cite} 
\usepackage{url}  
\usepackage{ifthen} 
\usepackage{multicol}  
\usepackage[utf8]{inputenc} 
\usepackage{graphicx}
\usepackage{graphicx,epsfig}
\usepackage{amssymb,amsmath}
\usepackage{subfigure}
\usepackage{epstopdf}
\usepackage{float}
\usepackage{algorithm2e}
\usepackage{multirow}  

Just had no idea why it happened? Please help.

1

2 Answers 2

43

Since the algorithm and algorithm2e packages both define an algorithm environment, simply loading both with no extra precaution will cause a name clash like you experienced.

However, you can still use both packages (if you really need both), but you need to pass the option algo2e to algorithm:

\usepackage[algo2e]{algorithm2e} 

This option changes the name of the environment algorithm from the algorithm2e package into algorithm2e and so avoids the conflict with the package which already define an algorithm environment; the option also changes the command name for the list of algorithms to \listofalgorithmes.

A complete example:

\documentclass{article}
\usepackage{algorithm} 
\usepackage{algorithmic}  
\usepackage[algo2e]{algorithm2e} 

\begin{document}

\begin{algorithm}%>- from algorithm package
test
\end{algorithm}

\begin{algorithm2e}%>- from algorithm2e package
test
\end{algorithm2e}

\end{document}

enter image description here

1
  • Thanks. It resolved my question. But now the line number cannot be set
    – GoingMyWay
    Jan 16, 2022 at 8:13
3

The algorithms bundle (which provides the algorithm and algorithmic packages) is not compatible with algorithm2e. The latter is self-contained, providing both the floating environment algorithm (also provided by algorithms' algorithm package) as well as programming constructs (like If, Else, While, etc).

In terms of your algorithm layout, you have to choose - either construct your algorithms using elements from the algorithms bundle, or algorithm2e.

You must log in to answer this question.

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