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.

1 Answer 1


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

enter image description here

\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
  commentstyle=\color{white}, % white comments
  stringstyle=\ttfamily, % typewriter type for strings
  showstringspaces=false} % no special string spaces
  \caption{A normal figure}
for i:=maxint to 0 do
{ do nothing }
Write(’Case insensitive ’);
WritE(’Pascal keywords.’);
\caption{This is a listing}

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, 2012 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, 2012 at 23:22

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .