Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I have this algorithm:

\begin{algorithm}
\captionsetup[algorithm]{name=MegaAlgorithm}

\DontPrintSemicolon
\KwData{$G=(X,U)$ such that $G^{tc}$ is an order.}
\KwResult{$G’=(X,V)$ with $V\subseteq U$ such that $G’^{tc}$ is an
interval order.}

\caption{\textsc{Fast}SLAM\label{IR}}
\end{algorithm}

Using these packages:

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

But the label name of my algorihm is still 'Algorithm 1: FastSLAM' instead of 'MegaAlgorithm 1: FastSLAM'. How to do that?

share|improve this question
    
I think you need to recompile yoor source several times to overwrite *.aux and other files. –  m0nhawk Mar 26 '13 at 17:52
    
I'm using rm *.ps *.log *.aux *.dvi in my Makefile. So *.aux files should be overwriten. –  Petr Přikryl Mar 26 '13 at 18:02
1  
\captionsetup[algorithm]{name=MegaAlgorithm} after \begin{algorithm} is too late since the options declared with \captionsetup[algorithm]{...} will be used at \begin{algorithm}. So try \captionsetup[algorithm]{name=MegaAlgorithm} within your preamble instead, or as an alternative try \captionsetup{name=MegaAlgorithm} after \begin{algorithm}. But since the caption package is not adapted to the algorithm2e package there is a big chance that this will actually not work. –  Axel Sommerfeldt Mar 27 '13 at 6:04

2 Answers 2

up vote 6 down vote accepted

For the sake of consistency, define a new environment that uses the MegaAlgorithm caption style. Not sure whether you will intermix regular Algorithms and MegaAlgorithms, which this solution is geared towards:

enter image description here

\documentclass{article}
\usepackage[ruled,vlined]{algorithm2e}% http://ctan.org/pkg/algorithm2e
\usepackage{caption}% http://ctan.org/pkg/caption
\newenvironment{megaalgorithm}[1][htb]
  {\renewcommand{\algorithmcfname}{MegaAlgorithm}%
   \begin{algorithm}[#1]%
  }{\end{algorithm}}
\begin{document}
\begin{megaalgorithm}
\DontPrintSemicolon
\KwData{$G=(X,U)$ such that $G^{tc}$ is an order.}
\KwResult{$G’=(X,V)$ with $V\subseteq U$ such that $G’^{tc}$ is an
interval order.}
\caption{\textsc{Fast}SLAM\label{IR1}}
\end{megaalgorithm}
\begin{algorithm}
\DontPrintSemicolon
\KwData{$G=(X,U)$ such that $G^{tc}$ is an order.}
\KwResult{$G’=(X,V)$ with $V\subseteq U$ such that $G’^{tc}$ is an
interval order.}
\caption{\textsc{Fast}SLAM\label{IR2}}
\end{algorithm}
\end{document}

The new megaalgorithm environment redefines \algorithmcfname - the macro used to print the caption type - just before calling the regular algorithm environment. Since the redefinition is within the scope of megaalgorithm, it is localized and reverts back to the default afterwards. This allows you to intermix the different kinds of algorithm types.

share|improve this answer

Its simpler:

With algorithm2e package, solution will be as follows: [ My working copy of algoithm2e.sty is here ]

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

\begin{algorithm}
 \SetAlgorithmName{MegaAlgorithm}{} %last arg is the title of listing table
   ...
 \caption{How to write algorithm}
\end{algorithm}

Aside, since there is a considerable community using algorithmicx package (especially IEEE authors), here is the solution of the same problem with algorithmicx package:

\usepackage{algorithmicx}
\usepackage[Algorithm,ruled]{algorithm}
.
.

\begin{algorithm}
 \floatname{algorithm}{MegaAlgorithm}
  \begin{algorithmic}
    ...
  \end{algorithmic}
 \caption{How to write algorithm}
\end{algorithm}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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