4

I've tried using both algorithm2e and algorithmic to generate a list of algorithms, but they both do it this way:

List of Algorithms

1 BFS ..... 1
2 DFS ..... 2
...

When I'd like to it to be:

List of Algorithms

Algorithm 1 BFS ..... 1
Algorithm 2 DFS ..... 2
...

The packages being used:

\documentclass[pnumabnt,normaltoc,capchap,floatnumber=continuous]{abnt}  
\usepackage[bibjustif,abnt-etal-cite=2,abnt-full-initials=yes]{abntcite}
\usepackage[toc,page]{modelo/tex/appendix}
\usepackage[portuguese,brazilian,portuges]{babel}
\usepackage[utf8]{inputenc}
\usepackage{abnt-alf}
\usepackage{graphicx}
\usepackage{multicol}
\usepackage{listings}
\usepackage{booktabs}
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{eucal}
\usepackage{amssymb}
\usepackage{mathrsfs}
\usepackage[portugues]{algorithm2e}
2

Isn't it obvious, that below the heading List of Algorithms only algorithms follow? Why mention 20 times Algorithm again?

One could start by redefining the counter presentation like

\renewcommand*{\thealgocf}{Algorithm~\arabic{algocf}}

But the list of contents requires modification, this could be done with a package like tocloft or titletoc or tocbasic.

For consistency it may be following to do the same for figures, tables, sections and so on. That seems odd to me.

  • 1
    i want algorithm for every instance for consistency with the list of tables and figures. they followed a model so i can't help it. also, could you explain better how to fix it? i don't follow, sorry i'm new to latex. – bada Aug 9 '10 at 20:20
  • also, it seems that to use that \renewcommand I have to specify the margin/spacing or else "Algorithm" is garbled along the beginning of the Algorithm name. Is there a parameter for that? – bada Aug 9 '10 at 20:33
  • 1
    It's unclear which document class and which packages (captions, tocloft etc.) you're using. Provide a reduced but compilable example showing what you're actually doing. Especially what you mean with following a model and how it's already done with figures and tables. If I would just guess and post an example it would be unclear if it fits to your code. – Stefan Kottwitz Aug 9 '10 at 20:36
  • well, i can post the packages i'm importing, but i can't post the model here. if that isn't enough for you to answer i understand. – bada Aug 9 '10 at 20:49
  • You could insert dummy algorithm text, figures and tables- fire up the Lorem Ipsum generator. – Sharpie Aug 9 '10 at 20:57
1

The construction of the List of Algorithms uses the \l@algocf macro (or at least when I use the algorithm2e package it does). This may be slightly different depending on your algorithm package/settings/...

Anyway, you could place the following in the preamble in order to change the way that lines in the TOC are drawn:

\makeatletter
\let{\oldl@algocf}{\l@algocf}
\renewcommand{\l@algocf}[2]{\oldl@algocf{Algorithm #1}{#2}}
\makeatother
  • The first and last lines simply allow you to use the @ character in macro names.
  • The second line makes a copy of the original \l@algocf macro (so you can call it on the 3rd line)
  • The third line redefines the \l@algocf macro to insert the word Algorithm before the first argument (the caption text) in the TOC line.
  • gives me an error :( (! Missing control sequence inserted. <inserted text> \inaccessible l.57 \let{\oldl@algocf}{\l@algocf}) – bada Aug 18 '10 at 5:50
  • I think this means your algorithms TOC isn't getting generated with \l@algocf. Check the documentation of your algorithms package to see if you can find what its using to generate the TOC lines (it'll almost definitely be a macro starting with \l@ and ending with cf). In some packages, the name of that function is generated from the naming of your algorithm environment (e.g. you might define the "algo" or "algorithm" environment so as to be different from "theories" "examples" "lemmas" etc... in which case the documentation should specify how it generates that macro name) – drfrogsplat Aug 19 '10 at 2:26
0

I finally solve this problem correctly.

First, the solution proposed by Stefan Kottwitz doesn't solve the problem in algorithm2e package, cause the command \thealgocf although is used to represent the numeration in list of algorithms, it's is also used in titles for algorithm environment. Also the new name is cropped with the number as reported here.

So backing to drfrogslap answer, the idea was right, just \let expression was wrong. So to fix this and solve the problem just use the follow code:

\makeatletter
\let\oldl@algocf\l@algocf
\renewcommand{\l@algocf}[2]{\oldl@algocf{Algorithm #1}{#2}}
\makeatother

Thanks drfrogslap for the answer.

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.