2

I have two tex files, i.e., main.tex and supplementary.tex.

For supplementary.tex, I have three requirements:

  1. Captions of figures start with prefix 'Figure S'. So I set,
\documentclass{article}
\usepackage{xr-hyper}
\usepackage{hyperref}
\usepackage{cleveref}
\renewcommand{\figurename}{Figure S}
\begin{document}
% some supplementary materials
\end{document}
  1. There are no spaces between caption prefix and index. To be specific, I want to have 'Figure S1' rather than 'Figure S 1' in captions. So I set,
\def\fnum@figure{\figurename\thefigure}
  1. Citations of figures start with 'Supplementary Figure'. That is when we cite a figure, let's say the first figure, I want to have 'Supplementary Figure 1', here I used \autoref command and set
\renewcommand{\figureautorefname}{Supplementary Figure}

When I cite a figure, I did

\autoref{figurelabel}

For this supplementary.tex file, all requirements are realized.

For main.tex, I have two requirements:

  1. Citations of figures from supplementary also start with the prefix 'Figure S'. So I set
\documentclass{article}
\usepackage{xr-hyper}
\usepackage{hyperref}
\usepackage{cleveref}
\externaldocument[supp-]{supplementary} % for cite the external supplementary tex file
\renewcommand{\figureautorefname}{Figure S}

When I cited figures from the supplementary in this main file, I did

\autoref{supp-figurelabel}

However, this resulted that citations of figures belonging to main.tex also started with 'Figure S' rather than 'Figure'

  1. Citations of figures from supplementary have no spaces between the prefix and title. I can not do this because of similar reasons as the last case.

In summary, for supplementary.tex, everything seems ok. But how can I realize my requirements for main.tex?

6
  • Please clarify the nature of supplementary.tex. Is it an individually compilable file , i.e., does it have its own \documentclass, \begin{document}, and \end{document} statements? Or is "just" a collection of text and LaTeX macros?
    – Mico
    Jul 18, 2020 at 11:32
  • @Mico I have updated it. Thank you!
    – Jie
    Jul 18, 2020 at 11:42
  • If I understand your setup correctly, the captions of the figure environments in supplementary.tex say Figure S1, Figure S2, etc. Second, when they're cross-referenced from within supplementary.tex the cross-referencing call-outs are supposed to say Supplementary Figure 1, Suplementary Figure 2, i.e., *without* the S` prefix. Third, when they're cross-referenced from within main.tex, the call-outs are supposed say Figure S1, Figure S2, etc. Is this interpretation correct?
    – Mico
    Jul 18, 2020 at 12:00
  • @Mico Yes, you are right.
    – Jie
    Jul 18, 2020 at 12:26
  • Thanks. What readers of supplementary.pdf will probably find confusing (and maybe even bizarre) is that the captions of the figures say Figure S1, Figure S2, etc., yet cross-referencing call-outs to these figures, prpduced by \autoref or \cref, say Supplementary Figure 1, Supplementary Figure 2, etc. What's the purpose of this discrepancy? If the cross-referencing call-outs to the supplementary figures could be set to say Figure S1, Figure S2, etc in both main.pdf and supplementary.pdf, the formatting task would be much simpler -- and readers might be less confused.
    – Mico
    Jul 18, 2020 at 13:19

1 Answer 1

1

Thanks for clarifying the structure of supplementary.tex and for noting that Supplementary Figure 1, Supplementary Figure 2, etc will occur in section headers, not in "ordinary" cross-referencing call-outs.

Since the cross-referencing needs in supplementary.tex are very narrowly defined, I believe it makes sense to set up an extra counter variable and to increment it (via \refstepcounter) after each \caption statement, and to associate a separate \label with each value of the extra counter. As the following code shows, this is fairly easy to implement and, very importantly, doesn't interfere in any way with the usual \label, \autoref, and \cref measures.

Here, then, is how I would set up supplementary.tex:

enter image description here

\documentclass{article}
\usepackage{xr-hyper}
\usepackage[colorlinks,allcolors=blue]{hyperref}
\usepackage[nameinlink,noabbrev,capitalize]{cleveref}

\renewcommand\thefigure{S\arabic{figure}} % modify \thefigure, *not* \figurename
\newcounter{myfig} % create an extra counter variable

\begin{document}

\section*{Supplementary Figure \ref*{myfig:a}}
\begin{figure}[h]
\caption{A supplementary figure}
\label{fig:a} 
\refstepcounter{myfig}\label{myfig:a} % <-- increment and \label the extra counter
\end{figure}

\section*{Supplementary Figure \ref*{myfig:b}}
\begin{figure}[h]
\caption{Another supplementary figure}
\label{fig:b} 
\refstepcounter{myfig}\label{myfig:b} % <-- increment and \label the extra counter
\end{figure}

\end{document}

Of course, if you wanted to cross-reference the figures with \cref calls, you can certainly do so.


And here's how I would structure main.tex:

enter image description here

\documentclass{article}
\usepackage{xr-hyper}
\usepackage[colorlinks,allcolors=blue]{hyperref}
\usepackage[nameinlink,noabbrev,capitalize]{cleveref}
\externaldocument[supp-]{supplementary} 

\begin{document}
\noindent
\cref{fig:1}, \cref{supp-fig:a,supp-fig:b}

\begin{figure}[h]
\caption{A main figure}
\label{fig:1}
\end{figure}
\end{document}
1
  • 1
    Thank you so much!
    – Jie
    Jul 18, 2020 at 14:39

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .