Graphics, Figures & TablesReferencing a "non-existing" figure

Information and discussion about graphics, figures & tables in LaTeX documents.
Post Reply
katka
Posts: 2
Joined: Mon Nov 16, 2015 12:55 pm

Referencing a "non-existing" figure

Post by katka »

Hi all,
I have a question which would make writing in LaTeX easier for me. The short version of the question is: "Is it possible to create a custom label (as a reference to a figure, table, e.g. in the preamble), which can be later in the document referenced using the \ref command?"

Now the longer version: I use LaTeX for writing scientific articles. They are often composed of two separate documents (main text and supplementary info), which are designed as separate files (pdfs). (I tried using a single .tex file for both documents, but then there are other problems with formatting and using templates, so it does not simplify the original problem.) This means that I need to make references to figures which are included in a different file. If the figures in the main text are numbered as 1, 2, 3,... and in the supplementary info as S1, S2, S3,... the obvious solution, and the one I use, is to create a new command for referencing Figure S1 in the main text:

Code: Select all

\newcommand{\fGraph}{Fig.~S1}
and use it instead of the \ref command.

The problem with this solution is that during the revision process a lot of figures might need to be moved between the main text and the supplementary info; so if I need to move original Fig.~2 (say it was labeled \label{fResults}) from main text to supplementary info and rename it to Fig.~S3, I have to "manually" find all references to Fig.~2 using the \ref{fResults} command and replace them with a command \fResults (defined as \newcommand{\fResults}{Fig.~S3}). When I move more figures and also have to consider subfigures, there are always some mistakes.

So, is it possible to use something like:

Code: Select all

\mylabel{fResults}{S3}
(in the preamble, not in a figure environment)
and later in the document reference to this label using:

Code: Select all

Fig.~\ref{fResults}
?

Thanks a lot!

Katka

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

And: Currently, Packt sells ebooks for $4.99 each if you buy 5 of their over 1000 ebooks. If you choose only a single one, $9.99. How about combining 3 LaTeX books with Python, gnuplot, mathplotlib, Matlab, ChatGPT or other AI books? Epub and PDF. Bundle (3 books, add more for higher discount): https://packt.link/MDH5p

cgnieder
Site Moderator
Posts: 2000
Joined: Sat Apr 16, 2011 7:27 pm

Referencing a "non-existing" figure

Post by cgnieder »

Are the external files LaTeX files, too? If yes then the xr package might be what you need.

Regards
site moderator & package author
katka
Posts: 2
Joined: Mon Nov 16, 2015 12:55 pm

Re: Referencing a "non-existing" figure

Post by katka »

Thank you, the xr package seems to work!
Post Reply