I'm using the "listings" package to write pieces of code (XML, RDF, Java, etc) and I want them to have the same counter of the Figure environment.
For example,
Listing 1: blablabla
Listing 2: blebleble
Figure 3: bliblibli
Listing 4: blobloblo
Figure 5: blublublu
The purpose of doing it is to change the "Listing" label to "Figure". But I need both environments to share the same counter. How I do it?
Thanks in advance.
Best Answer
You can make things so the
figure
environment shares the counter withlstlisting
. However, you should ensure thatlstlisting
environments are floating too, otherwise the numbers could not agree and a figure could appear before a listing with a lower number.Thanks to David Carlisle for noting the need for adjusting
\ftype@lstlisting
.If you also want that
table
shares the counter, add similar instructions.