# Undefined reference when trying to reference figure from within appendix file

I have created a separate appendix file and have some figures in this file. I am trying to reference these figures in the text contained in the same file. However, I get undefined reference in the output file - ?? instead of the figure number. I also made sure that my caption for each figure was defined before the corresponding label. Moreover, it worked properly when I had it all in the main file (before I created a separate appendix). Here is my code - I have removed the content and only kept the formatting.

# Main file:

 \documentclass[aps,pra,twocolumn,showpacs,amsmath,amssymb,preprintnumbers,superscriptaddress,10pt]{revtex4-1}

\usepackage{graphicx}
\graphicspath{{figures/}}
\usepackage{hyphenat}
\usepackage{color}
\usepackage{url}
\usepackage[bookmarks=false]{hyperref}
\usepackage[capitalise]{cleveref}
\crefname{section}{Sec.}{Secs.}% APS style uses abbreviations
\Crefname{section}{Section}{Sections}
\usepackage[retainplus]{siunitx}
\usepackage[normalem]{ulem} % for the \sout command. Delete when finalized
\usepackage[titletoc]{appendix}

\begin{document}

\begin{appendices}
\include{Appendix_A}
\end{appendices}

\end{document}


# Appendix file (titled Appendix_A):

\section{Appendix}

Figure\ref{fig.PMF} shows something.

\begin{figure}
\includegraphics[width=0.90\linewidth]{example-image}
\caption[content 1]{content 2}
\end{figure}\label{fig.PMF}

• \label has to be inside the figure (unrelated to appendix markup) (although the markup shown would produce the wrong reference rather than undefined reference warning) it is always better to post a complete small document that shows the problem, as it is impossible to debug your fragments of code. – David Carlisle May 29 at 9:34
• Changed it. The above code reproduces the error. You would need to have a file called "PMF.pdf" in your working directory to run it. – IanDsouza May 29 at 11:05
• you can use example-image as the image which is generally available for tests or in this case simply delete the \includegraphics as the reference does not need an image, just a caption. – David Carlisle May 29 at 11:20
• thanks for the test case, that's weird, looking now... – David Carlisle May 29 at 11:24

You can simplify the test file to

\documentclass[aps,pra,twocolumn,showpacs,amsmath,amssymb,

\usepackage{graphicx}
\usepackage[titletoc]{appendix}

\begin{document}

\begin{appendices}
\include{Appendix_A}
\end{appendices}

\end{document}


there seems to be a bad interaction here with revtex and the appendix package which ends up breaking the \include mechanism. If you change that to

\input{Appendix_A}


Then it all works as intended.

• Thanks very much. That worked. I also placed the label inside the figure handle because it showed the wrong reference. – IanDsouza May 29 at 13:21