## Properly add a List of Listings in LaTeX

Hi folks,
today I’d like to show you how to properly add a “List of Listings” using the listings package to your LaTeX document. Before we start you have to include the listings package:
\usepackage{listings}

Then you can (if you like to) change the title of the section. By default it is named “Listings”. Here I change it to “List of Listings”:
\renewcommand{\lstlistlistingname}{List of Listings}

These two commands were outside the begin{document}, so the following ones will be inside.

Now we have to add a listing
\begin{lstlisting}[caption={ANSI C Hello World},label={lst:c_helloworld}] #include <stdio.h>

 

int main(void) { printf("Hello World\n"); return 0; } \end{lstlisting}

And finally here is the code which properly adds the List of Listings (also to the ToC)
% List of Listings \newpage \phantomsection \addcontentsline{toc}{section}{\lstlistlistingname} % Add it to the ToC \lstlistoflistings % The list itself

Hope this helps 😉

gr33z,
g0hl1n