Graphics, Figures & TablesWord "Algorithm" in LoA Entries

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
ahmedsalahais
Posts: 14
Joined: Sat Mar 19, 2011 11:17 pm

Word "Algorithm" in LoA Entries

Post by ahmedsalahais »

Hi all,

my document contains a lot of figures, tables, and algorithms. I'm able to produce LoF, LoT, and LoA. The problem is that I made it possible to have the word "Table" before any entry in LoT using \cfttabpresnum, the same with LoF using \cftfigpresnum. Now the question is how to do the same with List Of Algorithms (LoA)?


Thanks in advance,
Ahmed Salah

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

Stefan Kottwitz
Site Admin
Posts: 10335
Joined: Mon Mar 10, 2008 9:44 pm

Word "Algorithm" in LoA Entries

Post by Stefan Kottwitz »

Hi Ahmed,

it depends on how you produce the list of algorithms.
Perhaps show your way with a small Infominimal working example, which shows a tiny document with a LOA together with the chosen TOC or algorithm packages, there are several possible.

Stefan
LaTeX.org admin
ahmedsalahais
Posts: 14
Joined: Sat Mar 19, 2011 11:17 pm

Word "Algorithm" in LoA Entries

Post by ahmedsalahais »

Thanks for the reply. Here's my MWE:

Code: Select all

\documentclass[a4paper, 12pt, openany]{book}
\usepackage{tocloft}
\usepackage{algorithmic}
\usepackage[algochapter, algoruled, vlined]{algorithm2e}

\begin{document}
	\listofalgorithms

\chapter{Test}

\begin{algorithm}[htpb]
    \caption{Test Algorithm}
    \label{alg:test}
    \begin{algorithmic}[1]
        \STATE Just a test statement
    \end{algorithmic}
\end{algorithm}

\end{document}
User avatar
Stefan Kottwitz
Site Admin
Posts: 10335
Joined: Mon Mar 10, 2008 9:44 pm

Word "Algorithm" in LoA Entries

Post by Stefan Kottwitz »

Ok, with this MWE this code works:

Code: Select all

\makeatletter
\renewcommand*{\l@algocf}[2]{\@dottedtocline{1}{1em}{2.3em}{Algorithm #1}{#2}}
\makeatother
It's calling \@dottedtocline, as the original algorithm2e code does, but inserts Algorithm before the number.

It seems algorithm2e doesn't directly work with tocloft, so the change is not made with tocloft.

Stefan
LaTeX.org admin
ahmedsalahais
Posts: 14
Joined: Sat Mar 19, 2011 11:17 pm

Re: Word "Algorithm" in LoA Entries

Post by ahmedsalahais »

That did the trick, Thank you so much Stefan.
Post Reply