18

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.

25

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

2

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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