7

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.

0
6

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 of figure environments, the relevant counter variable is called figure as well. The figure counter gets incremented when \caption{...} is run inside a figure 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 the figure 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.

enter image description here

\documentclass{article}
\usepackage{graphicx}
\usepackage[colorlinks]{hyperref}

\begin{document}
A cross-reference to the \hyperlink{fig:test}{figure} on the next page.   
\clearpage 

\begin{figure}
    \includegraphics[width=\textwidth]{example-image-a}
    \hypertarget{fig:test}{} % Note: 2nd arg is deliberately left blank
\end{figure}
\end{document}
0
7

\captionlistentry (offered by the caption package) does increment the figure counter as well, so you get a valid reference, too, by simply replacing \caption with \captionlistentry:

\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}
    \captionlistentry{}
    \label{Fig:test}
\end{figure}

\end{document}

Pros: This works with and without hyperref, and you could still have a "List of Figures" if wanted.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.