Introduction.
I am cross-referencing tables and figures from a supplementary.tex
file to a main.tex
file, by using the xr
package and the latexmkrc
file (I copied and pasted the latexmkrc
file from Cross referencing with the xr package in Overleaf). In other words, in the main.tex
file, I need to "call" the references of figures and tables, which are defined in the supplementary.tex
file. My MWE is the following:
supplementary.tex
\documentclass{article}
\usepackage{hyperref}
\usepackage{graphicx}
\usepackage{subcaption}
\usepackage{cleveref}
\begin{document}
\section{Tables}
\label{supp_table}
\begin{table}[ht]
\centering
\begin{tabular}{ll}
\hline material & T [K] \\ \hline
Sn & 3,7 \\
Pb & 7,2 \\
Al & 1,2 \\ \hline
\end{tabular}
\caption{My table.}
\label{my_table}
\end{table}
\section{Figures}
\label{supp_fig}
\begin{figure*}[h]
\centering
\begin{subfigure}{0.4\textwidth}
\includegraphics[width=\linewidth]{figure1/test_figure_latex1}
\caption{Left}
\end{subfigure}
\begin{subfigure}{0.4\textwidth}
\includegraphics[width=\linewidth]{figure1/test_figure_latex2}
\caption{Right}
\end{subfigure}
\caption{My figure.}
\label{my_figure}
\end{figure*}
\end{document}
main.tex
\documentclass[12pt]{article}
\usepackage{hyperref}
\usepackage{cleveref}
\usepackage{xr}
\makeatletter
\newcommand*{\addFileDependency}[1]{
\typeout{(#1)}
\@addtofilelist{#1}
\IfFileExists{#1}{}{\typeout{No file #1.}}
}\makeatother
\newcommand*{\myexternaldocument}[1]{%
\externaldocument{#1}%
\addFileDependency{#1.tex}%
\addFileDependency{#1.aux}%
}
\myexternaldocument{supplementary}
\begin{document}
\noindent
In \Cref{supp_table} there is \Cref{my_table}.\\ \\
In \Cref{supp_fig} there is \Cref{my_figure}.
\end{document}
Question.
Once I am in the main.tex
file, how can I automatically add the word "Supplementary" to the referenced figures and tables which are defined in the supplementary.tex
file?
(in order to have the following names: "Supplementary Figure" and "Supplementary Table")
Desired Output.
My desired is to get automatically the names "Supplementary Figure" and "Supplementary Table" as outputs of the main file as follows:
In this moment, instead, I am adding "by hand" the word "Supplementary" to each figure and table which were defined in the supplementary file.
Note after the @gusbrs solution.
To people interested in this topic and in the method here kindly provided by @gusbrs: you might be also interested in How can I pass the name of a section from a tex file to another (with "zref-clever")? and in the @gusbrs great solution!
\renewcommand{\figurename}{Supplementary Figure}
in thesupplementary.tex
file, hoping that the word "Supplementary" could be then displayed in the output of themain.tex
file, but it did not work...