On a local TeX installation, the code of the example in the question (almost) works. The required changes have nothing to do with the packages xr
and subfiles
, but just make the loading of the image work.
So if there are problems on Overleaf, they are caused by the specific setting there, not by the packages.
The file structure is as follows:
main.tex
section/discussion.tex
section/methodology.tex
Typesetting main.tex
and section/discussion.tex
works as usual: run latex
twice.
To typeset section/methodology.tex
, you have first to run latex
once on discussion.tex
(this produces discussion.aux
, which holds the labels from discussion.tex
), and then once on methodology.tex
(this run reads discussion.aux
):
cd section
pdflatex discussion
pdflatex methodology
Here is the contents of the three files.
% main.tex
\listfiles % to get the list of loaded packages with version information
\documentclass[conference]{IEEEtran}
\usepackage{graphicx}
\usepackage{xr}
\usepackage{subfiles}
\begin{document}
\section{Methodology} \label{methodology}
\subfile{section/methodology}
\section{Results and Discussion} \label{discussion}
\subfile{section/discussion}
\end{document}
% section/discussion.tex
\documentclass[../main.tex]{subfiles}
\begin{document}
\begin{figure}
\includegraphics[width=0.45\textwidth]{example-image}
\caption{My Figure.}
\label{fig:myfig}
\end{figure}
\end{document}
% section/methodology.tex
\documentclass[../main.tex]{subfiles}
\externaldocument{discussion}
\begin{document}
I want to refer to Figure \ref{fig:myfig}
\end{document}
For reference, here is the list of loaded packages with information on the versions used. You obtain it by adding \listfiles
as first line in main.tex
. The list appears at the end of the log output.
*File List*
IEEEtran.cls 2015/08/26 V1.8b by Michael Shell
ot1ptm.fd 2001/06/04 font definitions for OT1/ptm.
graphicx.sty 2017/06/01 v1.1a Enhanced LaTeX Graphics (DPC,SPQR)
keyval.sty 2014/10/28 v1.15 key=value parser (DPC)
graphics.sty 2019/11/01 v1.3d Standard LaTeX Graphics (DPC,SPQR)
trig.sty 2016/01/03 v1.10 sin cos tan (DPC)
graphics.cfg 2016/06/04 v1.11 sample graphics configuration
pdftex.def 2018/01/08 v1.0l Graphics/color driver for pdftex
xr.sty 2019/07/22 v5.05 eXternal References (DPC)
subfiles.sty 2019/10/30 v1.5 Multi-file projects (package)
import.sty 2009/03/23 v 5.1
supp-pdf.mkii
epstopdf-base.sty 2016/05/15 v2.6 Base part for package epstopdf
infwarerr.sty 2016/05/16 v1.4 Providing info/warning/error messages (HO)
grfext.sty 2016/05/16 v1.2 Manage graphics extensions (HO)
kvdefinekeys.sty 2016/05/16 v1.4 Define keys (HO)
ltxcmds.sty 2016/05/16 v1.23 LaTeX kernel commands for general use (HO)
kvoptions.sty 2016/05/16 v3.12 Key value format for package options (HO)
kvsetkeys.sty 2016/05/16 v1.17 Key value parser (HO)
etexcmds.sty 2016/05/16 v1.6 Avoid name clashes with e-TeX commands (HO)
ifluatex.sty 2019/10/25 v1.5 ifluatex legacy package. Use iftex instead.
iftex.sty 2019/11/04 v1.0b TeX engine tests
pdftexcmds.sty 2019/07/25 v0.30 Utility functions of pdfTeX for LuaTeX (HO)
ifpdf.sty 2019/10/25 v3.4 ifpdf legacy package. Use iftex instead.
epstopdf-sys.cfg 2010/07/13 v1.3 Configuration of (r)epstopdf for TeX Live
methodology.tex
discussion.tex
example-image.pdf Graphic file (type pdf)
***********
main.tex
outsidexr
you need the extra helper code andlatexmkrc
to get the.aux
formethodology.tex
when you're compiling (latexmk) fromdiscussion.tex
as a subfile. The technique actually comes from tex.stackexchange.com/questions/62142/…LaTeX
first ondiscussion.tex
and then onmethodology.tex
. On my local installation (not Overleaf) your code works fine (except that one has to add\usepackage{graphicx}
inmain
and replacemyfig.pdf
byexample-image
.@gernotsaysReinstateMonica
to your comment in order to notify me about your answer. Otherwise I will notice it only if I come back by chance.