# Problem and question tocloft

I tried to create my own "List of things" with help of this post: Define your own list of

Now my questions:

1. I don't want to use the command \algorithm {Text}. Instead I want to use a container like \begin{algorithm}...\end{algorithm}. How can I do this? (optional)
2. The List of Algorithms is empty even I use the first command. How can I fill it?
3. The headline looks different to the headlines of the "normal" lists.

Here is my example:

\documentclass[a4paper, oneside, 12pt, listof=totoc, bibliography=totoc, titlepage, headinclude = false, footinclude = false, mpinclude = false, BCOR = 0mm, DIV = calc]{scrartcl}
\usepackage[ngerman]{babel}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{lmodern}
\usepackage{graphicx}
\makeatletter

\def\ScaleIfNeeded{%
\ifdim\Gin@nat@width>\linewidth
\linewidth
\else
\Gin@nat@width
\fi
}\makeatother

\usepackage{setspace}
\onehalfspacing
\usepackage[a4paper, left=3 cm, right=4 cm, top=3 cm, bottom=1.5 cm]{geometry}
\usepackage{fancyhdr}
\usepackage{longtable}
\usepackage{bibgerm}
\usepackage{eurosym}
\usepackage{booktabs}
\usepackage{array}
\usepackage{color}
\usepackage{tabularx}
\usepackage{pdflscape}
\usepackage[justification=RaggedRight, singlelinecheck=false]{caption}
\usepackage[pageanchor=false]{hyperref}
\usepackage{listings}
\usepackage{algorithm}
\usepackage{etoolbox}
\usepackage{pdfpages}
\usepackage[scaled]{uarial}
\usepackage[printonlyused]{acronym}
\usepackage{bigstrut}
\usepackage{multirow}
\usepackage{acronym}
\usepackage{ulem}
\usepackage{tocloft}
\fancypagestyle{plain}{}
\pagestyle{fancy}
\fancyhf{}
\setcounter{secnumdepth}{5}
\setlength{\parindent}{0pt}

\newcommand{\listalgorithm}{Algorithmenverzeichnis}
\newlistof{Algorithmen}{algo}{\listalgorithm}
\newcommand{\Algorithmen}[1]{%
\refstepcounter{Algorithmen}
\par\noindent\textbf{Algorithmen \theAlgorithmen. #1:}
{\protect\numberline{\thechapter.\theAlgorithmen}#1}\par}

\begin{document}
listalgorithm
\newpage
\Algorithmen{My Algorithm}
\includegraphics[width=\ScaleIfNeeded]{../Bilder/node_init.png}


The last two lines should look like (this is optional)

\begin{Algorithm}
\caption{My Algorithm}
\includegraphics[width=\ScaleIfNeeded]{../Bilder/node_init.png}
\end{Algorithm}


And the heading of this algorithm list looks like:

List of Algorithm

But it should look like:

List of Algorithm

I hope I could explain my problem well enough ;)

P.S.: I searched for some posts but they did not fit to my problem :/

Edit: Okay I have tried both answers now and both are working.
My code looks nearly the same like the solutions, so I won't post it again. But I explain what my problem was.

cgnieder:
Everything works fine and looks how it should. My first problem was that I used the "algorithm" package and named the new toc algorithms too. So the package overwrote my commands. After I deleted it everything was fine.

Gonzalo:
Your solution nearly works fine too. The list looks like it should (bold headline and entries) but my other lists are not linked (anchored) in the pdf's menu. That seemes to be a problem with the "hyperref" package. After I commented and compiled nothing worked. But when I recommended it the list was created fine (except the anchors).

Because of the remaining problem and that the "tobasic" package is a class implemented package I chose cgnieders answer as my accepted one.

I thank you very much. You both helped me a lot!! Thank you!

• ...I made an edit to your question since the markdown wasn't really helping. If this was not correct, please edit your question accordingly. – Werner May 23 '13 at 20:28

I believe the most natural way with KOMA-Script would be to declare a new float via \DeclareNewTOC the same way I used in my answer to New figure environment. Note that you have to add a \caption{} and compile twice to get the list updated the same way as with the default floats {figure} and {table}:

\documentclass{scrartcl}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage[ngerman]{babel}

\DeclareNewTOC[%
type=algorithm,%
types=algorithms,% used in the \listof.. command
float,% define a floating environment
floattype=4,% see below
name=Algorithmus,%
listname={Algorithmenverzeichnis}%
]{loa}

% About the floattype' option:
% The numerical float type of the defined floats. Float types with common bits
% cannot be reordered. At the standard classes figures has float type 1 and tables
% has floatype 2. If no float type was given, 16 will be used.

% bold caption labels:
\setkomafont{captionlabel}{\bfseries}

% uncomment if you want the algorithms' numbered with 1.1 , 1.2, ... :
% \renewcommand\thealgorithm{\thesection.\arabic{algorithm}}

\begin{document}

\listoffigures

\listofalgorithms

\section{Foo Bar}

\begin{algorithm}
whatever
\caption{a caption}
\end{algorithm}

\end{document}


1) You can easily turn your command into an environment with the same functionality (see code below):

2) and 3) Use \listofAlgorithmen

\documentclass[a4paper, oneside, 12pt, listof=totoc, bibliography=totoc, titlepage, headinclude = false, footinclude = false, mpinclude = false, BCOR = 0mm, DIV = calc]{scrartcl}
\usepackage[ngerman]{babel}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{lmodern}
\usepackage[demo]{graphicx}
\usepackage{tocloft}

\makeatletter
\def\ScaleIfNeeded{%
\ifdim\Gin@nat@width>\linewidth
\linewidth
\else
\Gin@nat@width
\fi
}
\makeatother

\newcommand{\listalgorithm}{Algorithmenverzeichnis}
\newlistof{Algorithmen}{algo}{\listalgorithm}
\newenvironment{Algorithmen}[1]
{\refstepcounter{Algorithmen}
\par\noindent\textbf{Algorithmen \theAlgorithmen. #1:}\par\nobreak\noindent
{\protect\numberline{\thesection.\theAlgorithmen} #1}\ignorespaces%
}
{\par}

\begin{document}

\listoffigures
\listofAlgorithmen

\section{Test Section}
\begin{Algorithmen}{My Algorithm}
\includegraphics[width=\ScaleIfNeeded]{../Bilder/node_init.png}
\end{Algorithmen}

\end{document}


An image of the result:

Just out of curiosity, why don't you use one of the numerous dedicated packages to typeset algorithms?

I removed some packages from the original code that were not relevant for the problem. I also changed some chapter-related commands since the class used has to be scrartcl.

The demo option for graphicx simply replaces actual figures with black rectangles; do not use that option in your actual document.

• Thanks for the fast answer. 1. I tested the algorithms and listings environment but algorithms had "ugly" lines above and below the picture and I thought it would be easer to create a new one instead of renamin listings (I am not allowed to use listings as caption). If I use your code the environment works but the list itselfs looks like in my post. (small headline no entries) – j0chn May 23 '13 at 20:29
• @jOchn and are you using \listofAlgorithmen as suggested in my answer to generate the list? Notice also the change to screprt since you are using chapter-related commands. – Gonzalo Medina May 23 '13 at 20:37
• Ah okay I did not change to screprt. But I can't switch to screprt because LaTeX does not find that class and I use a lot of sections subsections and paragraphs. Can we change your solution to the scrartcl class? – j0chn May 23 '13 at 20:40
• @j0chn sure. Give me some seconds and I'll update the answer. – Gonzalo Medina May 23 '13 at 20:41
• @j0chn With KOMA-Script I think the natural way would be to declare a new float with the built-in \DeclareNewToc (I used it in my answer here tex.stackexchange.com/a/96493/5049 for example) – cgnieder May 23 '13 at 20:44