I am writing a paper that has an online appendix. The paper and appendix reference figures in each other. I'd like to be able to compile each of the documents as a separate .pdf file and maintain the figure referencing. The subfiles
package seems to work pretty well for this. But, there is a tiny flaw in that it seems to have difficulties when I also use the caption
package in order to modify, for example, how figure numbers appear. In essence, what happens is that if I also load the caption
package, then the hyperlinks in my appendix no longer work properly. When I compile the document, I get the following Warning:
LaTeX Warning: Label(s) may have changed. Rerun to get cross-references right.
Unfortunately, if I re-run the compilation, it breaks other references. Below is a minimal working example with more specific explanation of the procedure I'm trying to follow.
Main.tex
\documentclass{report}
\usepackage{subfiles}
\usepackage{xr-hyper}
\usepackage{hyperref}
\usepackage[notablist,nofiglist,nomarkers]{endfloat}
\usepackage{caption}
\begin{document}
\subfile{Body.tex}
\setcounter{page}{1}
\setcounter{figure}{0}
\setcounter{postfigure}{0}
\renewcommand{\thepostfigure}{\Alph{section}.\arabic{postfigure}}
\renewcommand{\thefigure}{\Alph{section}.\arabic{figure}}
\subfile{Appendix.tex}
\end{document}
Body.tex
\documentclass[Main.tex]{subfiles}
\begin{document}
\section{Section 1}
\label{sec:Section1}
\begin{figure}
\centering\rule{1cm}{1cm}
\caption{Body Figure 1}
\label{body_fig1}
\end{figure}
As I show in \autoref{fig1} in \autoref{sec:Online_Appendix} of the appendix ...
\processdelayedfloats
\end{document}
Appendix.tex
\documentclass[Main.tex]{subfiles}
\begin{document}
\pagebreak
\appendix
\section{Online Appendix}
\label{sec:Online_Appendix}
My discussion in \autoref{sec:Section1} is informed by \autoref{fig1} and \autoref{fig2} and \autoref{fig3}.
\begin{figure}
\centering\rule{1cm}{1cm}
\caption{Appendix Figure 1}
\label{fig1}
\end{figure}
\pagebreak
\begin{figure}
\centering\rule{1cm}{1cm}
\caption{Appendix Figure 2}
\label{fig2}
\end{figure}
\pagebreak
\begin{figure}
\centering\rule{1cm}{1cm}
\caption{Appendix Figure 3}
\label{fig3}
\end{figure}
\end{document}
Work Flow
- I first compile
Main.tex
. - I then comment out the
\subfile{Body.tex}
and recompileMain.tex
. This generates the proper text for the appendix, but the hyperlinks to the figures go to the wrong places in the document when clicked. This is where I get the warning about labels having changed. - If I recompile
Main.tex
again, the hyperlinks to the figures in the appendix now work, but the reference to the section inBody.tex
now appears as??
Comments
- All of this works fine if I don't have the
caption
package enabled. - If I just try to compile either
Body.tex
orAppendix.tex
separately, the cross references don't work correctly, which is why I use the procedure with the multiple separate compilations ofMain.tex
.