I would to include my listings as floats, pretty much as Figures, but I don't want to call them Figures. I want to call them listings. How can I do that?

  • Welcome to TeX.sx! Your question was migrated here from Stack Overflow. Please register on this site, too, and make sure that both accounts are associated with each other, otherwise you won't be able to comment on or accept answers or edit your question. – Werner Feb 22 '12 at 16:39

There are two packages that let you format your listings and are able to let them float.

Here are two simple examples.


    caption={Dummy Listing},

      Hello World!



        Hello World!
    \caption{Dummy listing}

The respective manuals have more details about customization of your listings.

  • 3
    Would be good to know the reason for the vote down. Without it's hard to improve. – Thorsten Donig Mar 16 '12 at 8:26

It would be possible to re-purpose the figure environment and associated macros, but it may make the code harder to read. For example,

  % <contents>

would then serve the (possibly) dual purpose of posting a listing or a figure. Additionally, what should be contained within \listoffigures?

The float package allows for the easy definition of new floats. Here's a minimal example declaring a new float listing, as well as the appropriate \listoflistings command to display a "List of Listings":

enter image description here

\usepackage{float}% http://ctan.org/pkg/float
% Create new "listing" float
\newcommand{\listoflistings}{\listof{listing}{List of Listings}}
  \caption{This is a figure}
Here is some code.
  \caption{This is a listing}

For more information on the user interface, consult the float package documentation.

  • 1
    New floats can also be created by the caption package. The classes of the KOMA-Script bundle offer this feature, too. – Thorsten Donig Feb 22 '12 at 17:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy