1

I would like to give one of my figures a custom tag. For equations this can be done using \tag{my string} to specify that the equation should be tagged as 'my string'. Is there any way to achieve a similar effect with a figure?

Edit: for clarity, by 'tag' I mean the number that is, usually, automatically generated by the caption command. I want to override this automatic process so that the figure 'number' is a string of my choice. I imagined this working something like

\tag{my tag} \caption{my caption}

To produce the caption text

Figure my tag: my caption

This doesn't seem to work though

2
  • 2
    What exactly do you mean by giving a figure a tag. One normally give a figure a caption, and then refer to the number this caption provides
    – daleif
    Nov 9, 2020 at 14:02
  • Edited to clarify
    – Eddy
    Nov 9, 2020 at 14:20

1 Answer 1

2

You can (locally) redefine \thefigure.

It's possible to use two “tagged” captions in the same figure environment, but not a normal and a tagged one.

\documentclass{article}

\newcommand{\figuretag}[1]{%
  \addtocounter{figure}{-1}%
  \renewcommand{\thefigure}{#1}%
}

\begin{document}

Normal figures \ref{normal1} and \ref{normal2}; tagged figure~\ref{tagged}.

\begin{figure}[htp]
\centering
\fbox{A normal figure}

\caption{Normal figure}\label{normal1}
\end{figure}

\begin{figure}[htp]
\centering
\fbox{A tagged figure}

\figuretag{(*)}
\caption{Tagged figure}\label{tagged}
\end{figure}

\begin{figure}[htp]
\centering
\fbox{A normal figure}

\caption{Normal figure}\label{normal2}
\end{figure}

\end{document}

enter image description here

If you need to load hyperref, the code should be

\documentclass{article}

\newcommand{\figuretag}[1]{%
  \addtocounter{figure}{-1}%
  \renewcommand{\thefigure}{#1}%
  \renewcommand{\theHfigure}{#1}%
}
3
  • This is great, thanks! I managed to track down a question titled 'Numbering a figure with a symbol in a way that is compatible with \label and \ref', and combining your answer with the one there arrived at the code \makeatletter \newcommand{\floattag}[1]{% \@namedef{the\@captype}{#1}% \@namedef{theH\@captype}{#1}% \addtocounter{\@captype}{-1}} \makeatother Is this going to work correctly for all floats (tables too)?
    – Eddy
    Nov 9, 2020 at 14:39
  • @Eddy That's essentially the same, but with generic floats.
    – egreg
    Nov 9, 2020 at 14:45
  • Great, that fixes it everywhere then!
    – Eddy
    Nov 9, 2020 at 14:46

You must log in to answer this question.

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