With xr
I can cross-reference labels in another document. With subcaption
I can refer to subfigures (or similar). But if I try to combine them both, it seems they don't recognise each other:
a.tex:
\documentclass{article}
\usepackage{subcaption}
\begin{document}
\section{Main}
\begin{figure}
\begin{subfigure}{0.5\textwidth}
A
\caption{}\label{fig:A}
\end{subfigure}
\begin{subfigure}{0.5\textwidth}
B
\caption{}\label{fig:B}
\end{subfigure}
\caption{A figure}\label{fig}
\end{figure}
See \ref{fig}, panels \subref{fig:A} and \subref{fig:B}.
\end{document}
b.tex
\documentclass{article}
\usepackage{subcaption}
\usepackage{xr}
\externaldocument[A-]{a}
\begin{document}
\section{Main}
See \ref{A-fig}, panels \subref{A-fig:A} and \subref{A-fig:B}.
\end{document}
After compiling a.tex
, b.tex
says:
LaTeX Warning: Reference `sub@A-fig:A' on page 1 undefined on input line 7.
LaTeX Warning: Reference `sub@A-fig:B' on page 1 undefined on input line 7.
If I change the \subref{A-fig:A}
to \ref{A-sub@fig:B}
, it seems to work as expected. Can the definition of \subref
be modified to make it compatible with xr
?
\ref{A-sub@fig:A}
internally. Easiest solution would be to give\subref
two arguments, as in\subref[A-]{fig:A}
.