I'd like to place some of my floats (specifically code listings) in my documents in a section at the end, without disturbing the numbering. Currently, I have them numbered within sections, so in section 1 all listings are called Program 1.1, Program 1.2 etc.

Is there a way to create a section at the end (like an appendix) where all the program floats go, without changing their numbering? Ideally, I'd like to have

Section 1
Some text in Section 1, and a reference to Program 1.1 and 1.2.

Section 2
Apparently Program 2.1 was the only code shown in this section.


Appendix A
Program 1.1:

for i = 1:n

Program 1.2:

% This program doesn't do anything


Before anyone shoots me for not showing exactly how the programs are defined, here's how it works:

% In the preamble


% In the document
  • I'm not sure, but this is perhaps relevant, how did you manage to number your programs by section using listings? Also, do you want to move all of the program listings to the end, or only some of them? Sep 28, 2010 at 12:26
  • @Juan: I have defined a new float environment using the floats package, but my question is not so much related to what kind of float it is than how to move them around. Sep 28, 2010 at 13:50
  • No, the question was more about how do you get the numbering per section, and also if you want all or some of them in the end. I'm thinking of a possible solution by hacking into the counters and temporarily make each appendix number as if it were in a previous section. Sep 28, 2010 at 15:23
  • Just got some minutes and posted a possible answer below. Sep 28, 2010 at 17:19

3 Answers 3


So this is my candidate solution which basically consists in manually moving all the floats to the end, and then temporarily hack into the section counter in order to show the desired numbers.






Please see Program~\ref{dostuff} and \ref{donothing}.

\section{Another thing}
Also see Program~\ref{onlyone}.




\section{Yet another appendix}


As the floats don't really need to “float” anymore, I would furthermore suggest to change their placement simply to “H” rather than “hbt”. Also I have no idea about the terrible things that this could cause if you're trying to use this together with hyperref.

  • I've tested this a little now, and it seems to work excellently with the hyperref package as well. Thanks! Sep 28, 2010 at 22:15

Here's a bit of a hack that might be suitable for what you need. I hope you don't mind the floats appearing on their own pages. See the FAQ answer on floats for something of an explanation here. The code is uncommented but you should be able to get the gist of it. Also, be aware that you won't be able to have more than 36 floats using this technique.




    \caption{Black square.}


\section{Begin document}
\section{End document}

Here are all the floats.

  • 2
    I can't believe that somebody arbitrarily decided that "36 floats ought to be enough for everybody". LaTeX is full of surprises.. Sep 28, 2010 at 19:04
  • That's 36 floats (18 without morefloat) that haven't yet been placed - big difference. Considering there were only 256 registers, total, at the time, and memory constraints were very real, the limit of 18 reserved slots is very sensible. Sep 29, 2010 at 2:13
  • (With eTeX we now have 2^16 instead of 2^8 slots and worrying about available registers isn't really an issue.) Sep 29, 2010 at 4:48

Juan A. Navarro, how can I modify your solution so that it works for figures, inclusive a List of Figures? I have tried the package endfloat for my figures but have encountered certain issues; that's why I am looking for an alternative way of putting all my figures in a separate Chapter in the end of my document but before the supplement.

  • Please stop posting comments as if they were answers. Jan 8, 2022 at 18:21
  • Thanks for your feedback, José! Please, tell me what should I do if I have questions regarding a post?
    – KMFWeb
    Jan 8, 2022 at 18:34
  • Post questions and answers and earn reputation. When your reputation reaches 50, you can start commenting posts. Jan 8, 2022 at 18:37
  • 1
    Thanks, José! I'll post my question to Juan A. Navarro as a new question then.
    – KMFWeb
    Jan 8, 2022 at 18:41

You must log in to answer this question.

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