I'm writing up solutions to a book. The book already has all its contents labeled as Figure 1.5
, Equation 2.13
etc. I'd like to label my own figures and equations without suffering any collisions with the main text. For example Figure S-1.5
or Equation S-2.13
might do. Is there a way to do this?
1 Answer
The number that appears in both figure captions and references is determined by the macro\thefigure
. It is effectively defined as \arabic{figure}
if you are using article
, and as \ifnum\value{chapter}>0 \thechapter.\fi\arabic{figure}
if you are using book
or report
. The macro \theequation
does the same thing for equations.
You can thus accomplish what you want by prepending S-
to the definitions of \thefigure
and \theequation
, like this:
\documentclass{article}
\usepackage{amsmath} %% <- for \eqref, optional
\let\theequationWithoutS\theequation %% <- store old definition
\renewcommand\theequation{S-\theequationWithoutS}
\let\thefigureWithoutS\thefigure %% <- store old definition
\renewcommand\thefigure{S-\thefigureWithoutS}
%% Alternative:
% \usepackage{etoolbox}
% \pretocmd{\theequation}{S-}{}{}
% \pretocmd{\thefigure}{S-}{}{}
\begin{document}
\begin{equation}\label{myeq}
\int_{-\pi/2}^{\pi/2} \frac1{1+\cos(x)^{\sin(x)}} \, \mathrm{d}x = \frac\pi2
\end{equation}
\begin{figure}
\centering
\rule{2cm}{2cm} %% black box
\caption{\label{myfig}This is a figure.}
\end{figure}
This sentence contains references to Figure~\ref{myfig} and Equation~\eqref{myeq}.
\end{document}
\ref
(so nocleveref
,nameref
,autoref
etc) then you could just do\newcommand{\myref}[1]{S-\ref{#1}}
.Figure 1.5
toFigure S-1.5
in the text, doesn't it? The figure itself will still be titledFigure 1.5
.