# Add listings to list of figures

I am using the listings package to display code in my document. is it possible to add the listings to the List of Figures. Instead of Listing, there should be Figure in the caption and it should share the same counter as the figures.

-

The easiest way to obtain this is to insert your listing directly into a figure environment:

\documentclass{article}
\usepackage{listings}% http://ctan.org/pkg/listings
\lstset{% general command to set parameter(s)
basicstyle=\small, % print whole listing small
keywordstyle=\color{black}\bfseries\underbar, % underlined bold black keywords
identifierstyle=, % nothing happens
stringstyle=\ttfamily, % typewriter type for strings
showstringspaces=false} % no special string spaces
\begin{document}
\listoffigures
\begin{figure}
\rule{150pt}{100pt}%
\caption{A normal figure}
\end{figure}
\begin{figure}
\begin{lstlisting}
for i:=maxint to 0 do
begin
{ do nothing }
end;
Write(’Case insensitive ’);
WritE(’Pascal keywords.’);
\end{lstlisting}
\caption{This is a listing}
\end{figure}
\end{document}


The above listing example was taken from the listings documentation (section 1.3 Figure out the appearance, p 5).

-
the problem now is that the listings cant start on one page and end on the next, cause the figure dont get split like the listings –  Cheetah Jul 10 '12 at 22:06
@Cheetah: That's true - floats are limited to a "moving box" that has to fit within the page, otherwise you run the risk of a breakable float being split over more than two pages. There are ways to address that and would most likely require you to drop the floating capability of the listing (and also fall outside the scope of this question). Please post it as a fresh one using the "Ask Question" link above. Follow-up questions like this are more than welcome! Please also include a link to this question to provide the background. –  Werner Jul 10 '12 at 23:22