From what I understand, in order to refer to a figure in the text and be able to access it via clicking, I use \label{}
, and then in the text I use \ref{}
, with the same name inside.
What I would like is for the figure to not have the caption appear, but to keep the numbering. So that in the text, there is still "1" that I can click to jump to the figure, but for there not to be "Figure 1" or "Figure 1: etc". If I try including \caption*{}
(as I've seen on other answers), the numbering goes away and is replaced with "??" which is not what I want (although it still goes the picture when I click it).
I think getting rid of the caption
package and associated uses of \caption{}
would do the trick normally, but within the same document later on, I am planning on cross-referencing to figures in a document that uses the captions and the caption
package quite heavily, so I figure I need to be able to have the caption
package here.
Example code below:
\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{caption}
\usepackage{graphicx}
\usepackage{hyperref}
\begin{document}
\section{Introduction}
Let's test this \ref{Fig:test}
\begin{figure}
\centering
\includegraphics[width=\textwidth]{example-image-a}
\caption{}
\label{Fig:test}
\end{figure}
\end{document}
Any help would be appreciated.
Best Answer
The standard LaTeX
\label
-\ref
cross-referencing mechanism relies on LaTeX making a successful association between (a) the argument of\label
and (b) the most-recently-incremented counter variable. In the case offigure
environments, the relevant counter variable is calledfigure
as well. Thefigure
counter gets incremented when\caption{...}
is run inside afigure
environment. However, because you've expressed a preference for not running\caption
instructions, this standard cross-referencing mechanism isn't available to you.Happily, though, a second mechanism is available, courtesy of the
hyperref
package which is loaded in your example. It provides the commands\hypertarget{}{}
and\hyperlink{}{}
, which you could use as follows:Write
\hypertarget{name}{some text}
to create a target somewhere inside thefigure
environment. (This is the sort-of equivalent of\label
.)Write
\hyperlink{name}{some other text}
to create a hyperlink elsewhere in the document. (That's the sort-of equivalent of\ref
.)Note that
name
has to be the same across the two commands. (Moreover,name
has to be unique to the item to be cross-referenced, for obvious reasons.) In contrast, the second fields -- "some text" and "some other text" in the code snippets shown above -- need not be the same. In fact, one or both of these text fields can be left empty, as is done in the example below.Compile the following code to see these recommendations in action. The red "figure" label is a clickable target; click on it from within a pdf browser and you'll be taken to the
figure
on the following page.