Restart float numbering with endfloat with labels
The counter postfigure
needs to also be reset, like so:
\documentclass{article}
\usepackage[demo]{graphicx}
\usepackage[nofiglist]{endfloat}
\begin{document}
\listoffigures
\clearpage
\section{Test}
As we see in figure \ref{fig1} (and also in supplemental figure \ref{figS1}) \ldots
\begin{figure}
\includegraphics{fig1}
\caption{ One. } \label{fig1}
\end{figure}
\processdelayedfloats
\clearpage
\appendix
\section{Appendix}
\renewcommand{\thefigure}{S\arabic{figure}}
\renewcommand{\thepostfigure}{S\arabic{postfigure}}
\setcounter{figure}{0}
\setcounter{postfigure}{0}
\begin{figure}
\includegraphics{figS1}
\caption{ Supplement, one. } \label{figS1}
\end{figure}
\processdelayedfloats
\end{document}
Output
The counter used for the numbering “in place” is called postfigure
, so also this one should be changed.
Here's a solution that exploits \appendix
. The instruction for changing the counter representation and resetting the counter is written in the .fff
file, so it will enter into action when the actual typesetting of figures takes place.
\documentclass{article}
\usepackage[demo]{graphicx}
\usepackage{endfloat}
\usepackage{etoolbox}
\makeatletter
\appto{\appendix}{%
\renewcommand{\thepostfigure}{S\arabic{postfigure}}%
\setcounter{postfigure}{0}%
\efloat@iwrite{fff}{%
\unexpanded{%
\renewcommand{\thefigure}{S\arabic{figure}}^^J%
\setcounter{figure}{0}^^J%
}%
}%
}
\makeatother
\begin{document}
As we see in figure \ref{fig1} (and also in supplemental figure \ref{figS1}) \ldots
\begin{figure}
\includegraphics{fig1}
\caption{One.} \label{fig1}
\end{figure}
\clearpage % not necessary, just to make the figure go to the next page
\appendix
\begin{figure}
\includegraphics{figS1}
\caption{Supplement, one.} \label{figS1}
\end{figure}
\renewcommand{\thefigure}{\arabic{figure}}
\end{document}
For producing the picture, the page height has been artificially reduced.
UPDATE
Unfortunately, endfloat
version 2.6 introduced a bug which will make it not work as expected, besides breaking the code above. The package changed \immediate\write
into \immediate\protected@write{}
, which is wrong because \immediate
cannot work in this situation.
Updated code:
\documentclass{article}
\usepackage[demo]{graphicx}
\usepackage{endfloat}
\usepackage{etoolbox}
\makeatletter
% fix the wrong code in endfloat.sty
\@ifundefined{protected@iwrite}{%
\let\protected@iwrite\protected@write
\patchcmd{\protected@iwrite}{\write}{\immediate\write}{}{}%
\def\efloat@iwrite#1{\expandafter\protected@iwrite\csname efloat@post#1\endcsname{}}%
}{}
% double 'unexpansion' now is needed
\appto{\appendix}{%
\renewcommand{\thepostfigure}{S\arabic{postfigure}}%
\setcounter{postfigure}{0}%
\efloat@iwrite{fff}{%
\unexpanded{\unexpanded{%
\renewcommand{\thefigure}{S\arabic{figure}}^^J%
\setcounter{figure}{0}^^J%
}}%
}%
}
\makeatother
\begin{document}
As we see in figure \ref{fig1} (and also in supplemental figure \ref{figS1}) \ldots
\begin{figure}
\includegraphics{fig1}
\caption{One.} \label{fig1}
\end{figure}
\clearpage % not necessary, just to make the figure go to the next page
\appendix
\begin{figure}
\includegraphics{figS1}
\caption{Supplement, one.} \label{figS1}
\end{figure}
\renewcommand{\thefigure}{\arabic{figure}}
\end{document}