[Tex/LaTex] algorithm2e Command \algorithm already defined

algorithm2ealgorithmsincompatibility

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.

Best Answer

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