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?
Asked
Active
Viewed 1,706 times
0
1 Answers
1
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}
Circumscribe
- 10,856

\ref(so nocleveref,nameref,autorefetc) then you could just do\newcommand{\myref}[1]{S-\ref{#1}}. – Marijn Jun 07 '18 at 09:05Figure 1.5toFigure S-1.5in the text, doesn't it? The figure itself will still be titledFigure 1.5. – Sebastian Oberhoff Jun 07 '18 at 09:14In case it wasn't clear: I'm not the author of the book.
– Sebastian Oberhoff Jun 07 '18 at 18:38\def\p@figure{Figure~}work? – Werner Jun 07 '18 at 18:52