I have a question regarding the topic: Place all floats last without changing numbering

How can I modify the 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 hence why I am looking for an alternative way of putting all my figures in a separate Chapter at the end of my document but before the supplement.

Is there a possibility to include multiple figures in format of a table?

%Input image&
%Aligned face&
\end{tabular}}{Fifth image}{fig:tabfig}
  • For figures and tables, see tex.stackexchange.com/questions/430603/… and tex.stackexchange.com/questions/439236/… Commented Jan 8, 2022 at 22:47
  • Ad "Is there a possibility to include multiple figures in format of a table?" Seems your code-snippet creates a single figure consisting of a table (created via the tabular-environment) containing several images. Please specify precisely what you need: Do you need a sequence of floating objects? Is "floating" not needed but you just need a series of images with captions (see the “caption outside float” facility of the package "caption"), probably arranged in terms of a tablar/longtable-environment? Commented Jan 9, 2022 at 16:09

2 Answers 2


You can maintain a stack where tokens for creating floats are accumulated.

In the example below

  • a token-stack is created via \NewStack{⟨macro⟩}.

  • tokens are appended to a token-stack via \AppendToStack{⟨macro⟩}{⟨tokens⟩}.

  • the tokens saved in a stack are "flushed" and the stack is emptied via \FlushAndClearStack{⟨macro⟩}.

  • the command

                          {⟨counters to step at the time of carrying out \StuffAndCountersToStack⟩}%
                          {⟨counters to reset and restore at the time of delivering the ⟨tokens⟩}%

    adds to the stack ⟨macro⟩

    • directive to open a local scope
    • directives to reset ⟨counters to reset and restore at the time of delivering the ⟨tokens⟩,
    • directives to reset \the⟨counter⟩ and \theH⟨counter⟩ of ⟨counters to reset and restore at the time of delivering the ⟨tokens⟩,
    • directives to adjust \the⟨counter⟩ and \theH⟨counter⟩ of ⟨counters to step at the time of carrying out \StuffAndCountersToStack⟩
    • ⟨tokens⟩
    • directives to restore ⟨counters to reset and restore at the time of delivering the ⟨tokens⟩,
    • directive to close the local scope

    and steps ⟨counters to step at the time of carrying out \StuffAndCountersToStack⟩.

  • the command

                          {⟨counters to step at the time of carrying out \StuffAndCountersToStack⟩}%
                          {⟨counters to reset and restore at the time of delivering the ⟨verbatimized material⟩ via \scantokens⟩}%
                          |⟨verbatimized material⟩|%

    does almost the same as the command \StuffAndCountersToStack. The difference is: The ⟨tokens⟩-argument is read and tokenized in verbatim-catcode-régime and therefore called ⟨verbatimized material⟩. Instead of just adding ⟨tokens⟩ to the stack ⟨macro⟩, directives are added to the stack ⟨macro⟩ to pass ⟨verbatimized material⟩ to \scantokens.

% With older LaTeX-releases uncomment the following line:
  \def\expandafter\noexpand\csname theH#1\endcsname{\csname theH#1\endcsname}%
  \def\expandafter\noexpand\csname the#1\endcsname{\csname the#1\endcsname}%
  \def\expandafter\noexpand\csname theH#1\endcsname{\csname theH#1\endcsname}%
  \def\expandafter\noexpand\csname the#1\endcsname{\csname the#1\endcsname}%
    \csname c@#1\endcsname=#2\relax
    \advance\csname c@#1\endcsname by 1 %
% If this was for a package, checking whether stack-macro is defined
% could be implemented for the sake of error-checking.
%=== \VerbatimToScantokensStuffAndCountersToStack ========================
%=== End of code of \VerbatimToScantokensStuffAndCountersToStack =========

% Load hyperref _after_ float !


\csname @ifundefined\endcsname{theHfigure}{}{%
\csname @addtoreset\endcsname{figure}{section}

% \ref without hyperlink:
\csname @ifpackageloaded\endcsname{hyperref}{%



Please see figure~\ref{fig:one} and \ref{fig:two} and \ref{fig:three}
and \ref{fig:four} in Appendix~\ref{app:allimg}.

\section{First section}
Delayed figure~\ref{fig:one} and delayed figure~\ref{fig:two} are defined in this section.

    \caption{First image}%

    \caption{Second image}%

\section{Second section}
Delayed figure~\ref{fig:three} is defined in this section.

                                            ?%<-start of verbatim-argument
% Indenting of source code does matter with verbatimized arguments!
1 AB % & _^~# } {
2 AB % & _^~# } {
    \caption{figure with verbatim}%
? %<-end of verbatim-argument

\section{Third section}
Delayed figure~\ref{fig:four} is defined in this section.

    \caption{Third image}%


\section{An appendix}\label{app:a}

A figure in appendix \myref{app:a}
\caption{A figure in appendix \myref{app:a}}

\subsection{A subsection of appendix \myref{app:a}}\label{app:allimg}

Here come all the delayed floats.



enter image description here

enter image description here

I suppose it would be only a few lines in expl3, but I am not yet so fluent in expl3 that I could type the appropriate expl3 code in a few minutes.

There are many expl3-luminaries here, whom I could not hold a candle and who would of the cuff do a much better job than I could do by fiddling around and reading interface3.pdf for hours.
But I "borrowed" expl3's \clist_map_function:nN for mapping elements of comma-lists as arguments to macros. ;-)
(I also have my own "old school code" for this sort of things, but pasting that here would imply another huge load of confusing code.)


Try this code.

UPDATE Begin numbering the figures with .1 in each section.



Move all the figures to the end using the command figfrom (one optional parameter and three mandatory: #1 (opt) figure configuration, #2 figure name, #3 caption, #4 label) within the environment fromsection{<section number of the figures>}


%%*****************  adapted from <<<<<<<<<<<<<<<<<<
%%  https://tex.stackexchange.com/questions/3491/place-all-floats-last-without-changing-numbering

\newenvironment{fromsection}[1]{% #1 section number

\newcommand{\figfrom}[4][]{% #1 (opt) figure specs, #2 figure name, #3 caption, #4 label
%% ***************************************** 

    Please see figures~\ref{fig:one} and \ref{fig:two} in section~\ref{app:allimg}.
    \section{Other stuff}
    See also figure~\ref{fig:three} on page~\pageref{fig:three}.        

    \section{All figures together}\label{app:allimg}
        \figfrom[width=50pt]{example-image-a}{First image}{fig:one}
        \figfrom[scale=0.5]{example-image-b}{Second image}{fig:two}
        \figfrom[height=270pt]{example-image-c}{Third image}{fig:three}

  • The numbering is 1.1, 1.2, 2.3. - How do I change the code to obtain 1.1, 1.2, 2.1, so that the numbering starts with .1 for each section? Otherwise, your code works great! Thanks, Simon!
    – KMFWeb
    Commented Jan 8, 2022 at 21:11
  • 1
    @KMFWeb In the definition of the environment fromsection behind \setcounter{section}{#1}% add \setcounter{figure}{0}%. If using hyperref, which must be loaded after the package float, ensure uniqueness of destination-names by also adding \renewcommand{\theHsection}{\arabic{section}} and after \renewcommand{\thefigure}{\arabic{section}.\arabic{figure}} adding \renewcommand{\theHfigure}{\theHsection.\arabic{figure}}. With fromsection you may wish to add restoring the figure-counter at the end of the environment in the same way in which the section-counter is restored. Commented Jan 9, 2022 at 11:36
  • @KMFWeb Please see the updated code to correct the figure numbers. You can follow Ulrich Diez's very good instructions for adding hyperlinks if you want. Commented Jan 9, 2022 at 18:23

You must log in to answer this question.

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