Renumbering or adding S to supplementary section

floats

I'm writing my thesis right now and I want to add a \section{Supplementary Section} at the end of every chapter. Is there any way I can add a S prefix to figures in the \section{Supplementary Section}, and be able to \ref{supplementary figure} with the prefix in the main text, without messing up the figure numbering for the rest of the chapter? So for example, in the main sections prior I would have Figure 2.1 to Figure 2.56, and then in the Supplementary Section I will have Figure S2.1 to Figure S2.12 etc. And I want to call for example in the main text "for further info refer to Figure S2.1"

The only solution I found is \renewcommand but that seems to change the prefix of all the figures. Is there another \begin{figure} command that's specific to supplementary figures as well?

Thank you!

Best Answer

For consistency, define your supplementary section via a command, say, \supplementarysection.

enter image description here

\documentclass{report}

\newcommand{\supplementarysection}{%
  \setcounter{figure}{0}% Reset figure counter
  \let\oldthefigure\thefigure% Capture figure numbering scheme
  \renewcommand{\thefigure}{S\oldthefigure}% Prefix figure number with S
  \section{Supplementary section}% Set supplementary section
  \let\oldchapter\chapter% Copy \chapter into \oldchapter
  \renewcommand{\chapter}{% Update \chapter
    \let\thefigure\oldthefigure% Copy \thefigure into \oldthefigure
    \let\chapter\oldchapter% Restore original \chapter
    \oldchapter% Call original \chapter
  }
}

\begin{document}

\tableofcontents
\listoffigures

\chapter{A chapter}
\section{A section}
\begin{figure}\caption{First figure}\end{figure}
\begin{figure}\caption{Second figure}\end{figure}
\supplementarysection
\begin{figure}\caption{Third figure}\end{figure}
\begin{figure}\caption{Fourth figure}\end{figure}

\chapter{Another chapter}
\section{Another section}
\begin{figure}\caption{First figure}\end{figure}
\begin{figure}\caption{Second figure}\end{figure}
\supplementarysection
\begin{figure}\caption{Third figure}\end{figure}
\begin{figure}\caption{Fourth figure}\end{figure}

\end{document}