0

I am referencing a figure from an Appendix in my main text, but I would like the reference to show the Appendix letter and figure number if it referencing a figure in the Appendix.

For example, right now when I reference figure 1 from the Appendix A, it only says .1 but I would like it to say A.1 in the main text. I have included all of my preamble (since I am not sure what parts are relevant), and the lines from my document and Appendix A.

Please note that I am using a template (aip) in Overleaf.

Here is the preamble and the relevant lines from my main text.

\documentclass[%
 aip,
% jmp,
% bmf,
% sd,
% rsi,
 amsmath,amssymb,
%preprint,%
 reprint,%
%author-year,%
%author-numerical,%
% Conference Proceedings
]{revtex4-1}

\usepackage{graphicx}% Include figure files
\usepackage{float}
\usepackage{dcolumn}% Align table columns on decimal point
\usepackage{bm}% bold math
\usepackage[mathscr]{euscript}% use for script letters
\usepackage[english]{babel}
\usepackage{multirow}% use for having parts of table cover multiple lines
%\usepackage{array,booktabs}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[nottoc]{tocbibind}
\renewcommand\bibname{References}
\usepackage{mathptmx}
\usepackage{gensymb}
\usepackage{amsmath}
\usepackage{xfrac}
\usepackage{nicefrac}
\usepackage{appendix}
\usepackage{hyperref}
\hypersetup{
  colorlinks=true,
  linkcolor=blue,
  citecolor=blue,
  urlcolor=black,
  hypertexnames=false
  }
%\usepackage{nameref}% loads gettitlestring
\usepackage{xpatch}
\makeatletter
\xpatchcmd{\@ssect@ltx}{\@xsect}{\protected@edef\@currentlabelname{#8}\@xsect}{}{}% Patch \<section>*
\xpatchcmd{\@sect@ltx}{\@xsect}{\protected@edef\@currentlabelname{#8}\@xsect}{}{}% Patch \<section>
\makeatother
\usepackage[pagewise]{lineno}% Enable numbering of text and display math
\linenumbers\relax % Commence numbering lines

% for response to reviewers
%\usepackage[dvipsnames]{xcolor}
\usepackage{soul}

\begin{document}

\preprint{AIP/123-QED}

...

\subsection{Identification of the Quasi-Steady Period}\label{sec:2C-Quasi-Steady}

since the time-averaged lift-coefficient $\overline{C_L}$ had become roughly constant across all $AR$, and ${Re}_g$ considered in this study (see Figure \mbox{\ref{fig:A1}}b).

...

\clearpage
\input{Writing/SupA}

\end{document}

Here are the relevant lines from my Appendix A.

\preprint{AIP/123-QED}

\setcounter{page}{1}
\renewcommand{\appendixname}{Supplementary Material}
\appendix
\section*{Supplementary Material A}\label{Supplementary Material A}

\setcounter{figure}{0}

\renewcommand\thefigure{\thesection.\arabic{figure}}
\begin{figure*}[ht!]
  \centering
  \includegraphics[]{Figures/SupA/FigA1/FigA1.pdf}
  \caption{I have removed the caption in my question.}
  \label{fig:A1}
\end{figure*}
  • The way \label works, the text is stored in the aux file, so if you want to produce two different texts using \ref, you will need two different labels, etc. usually this is automated, as in subfigure and \subref, but it really does create two labels in the aux file. – John Kormylo Sep 5 at 15:25
  • See tex.stackexchange.com/questions/380519/… for details. – John Kormylo Sep 5 at 15:35
  • @JohnKormylo I've read the link you suggested but I'm having trouble understanding it. This is compounded since in the second Appendix all the references are A.# instead of B.#. The issue seems to be that the labels are the correct style inside of Appendix B, but the first letter is wrong. Can you help me with a working example? – WnGatRC456 Sep 5 at 18:52
  • Actually, your mian problem is that \section* does not increment the section counter, and \thesection is blank (Alph{0}). – John Kormylo Sep 5 at 21:59
0

This shows how to create a second \label and \ref for the figure. I minimized your MWE a bit more.

\documentclass[%
 aip,
% jmp,
% bmf,
% sd,
% rsi,
 amsmath,amssymb,
%preprint,%
 reprint,%
%author-year,%
%author-numerical,%
% Conference Proceedings
]{revtex4-1}

\usepackage{appendix}

\makeatletter
\newcommand{\locallabel}[1]% #1 = label name
{\bgroup% temporary
  \edef\@currentlabel{\arabic{figure}}%
  \label{#1}%
\egroup}
\makeatother

\begin{document}
\listoffigures
\hrule
One can use \ref{fig:A1} or \ref{fig:1}.

\preprint{AIP/123-QED}

\setcounter{page}{1}
\renewcommand{\appendixname}{Supplementary Material}
\appendix

\section{Supplementary Material A}\label{Supplementary Material A}

\setcounter{figure}{0}
\renewcommand{\thefigure}{\thesection.\arabic{figure}}% defaul \ref and \listoffigures

\begin{figure*}[ht!]
  \caption{I have removed the caption in my question.}
  \label{fig:A1}
  \locallabel{fig:1}
\end{figure*}

\end{document}
| improve this answer | |
  • Actually, I think the problem can be fixed by replacing \section*{} with \section{} as you mentioned. It seems like this is built into the template on Overleaf. – WnGatRC456 Sep 6 at 13:19
  • 1
    If I am not mistaken, templates are responsible for most of the problems found on this site. – John Kormylo Sep 6 at 17:16
  • Fix one problem, and it causes another. – WnGatRC456 Sep 6 at 23:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.