1

Is there a way to customize the display of a subfigure reference like a \tag command does in an equation.

For example, the following MWE:

\documentclass{article}
\usepackage{subcaption}
\usepackage{cleveref}
\usepackage{tikz}

\def\exfigure#1{\centering
  \begin{tikzpicture}\path[draw=#1,fill=#1!20] (0,0) rectangle (4,4);\end{tikzpicture}}

\begin{document}
\begin{figure}
  \begin{subfigure}[b]{0.3\linewidth}
    \exfigure{red}
    \phantomsubcaption \label{subfig1}
    % \tag{\figurenum(red)}
  \end{subfigure}
  \hfill
  \begin{subfigure}[b]{0.3\linewidth}
    \exfigure{green}
    \phantomsubcaption \label{subfig2}
    % \tag{\figurenum(green)}
  \end{subfigure}
  \hfill
  \begin{subfigure}[b]{0.3\linewidth}
    \exfigure{blue}
    \phantomsubcaption \label{subfig3}
    % \tag{\figurenum(blue)}
  \end{subfigure}
  \caption{Three squares. Left: red. Center: green. Right: blue.}
  \label{fig:all}
\end{figure}

In \cref{fig:all}, we have three subfigures \cref{subfig1}
\cref{subfig2} and \cref{subfig3}.
\end{document}

In this example, cref displays

In fig. 1, we have three subfigures fig. 1a fig. 1b and fig. 1c.

I would like to instead have

In fig. 1, we have three subfigures fig. 1(red) fig. 1(green) and fig. 1(blue).

By customizing the labels as the invalid commented statement do, i.e., using something like \tag{\figurenum(red)}

I saw an answer here for a similar problem(where I took the MWE from). That answer has a more global solution for all subfigures and is based on the placement of the subfigures (or their number). It also does not use cleveref which I prefer to use.

Is there a way to customize the label for each figure/subfigure separately?

4
  • 1
    Somewhat related: tex.stackexchange.com/questions/423580/… Jun 30, 2021 at 13:43
  • That is actually exactly what I need! A command like \def\figtag#1{\renewcommand{\thesubfigure}{#1}} seems to work flawlessly. Thanks! If you write an answer I will accept it, otherwise I can answer my own question based on this comment.
    – Tohiko
    Jun 30, 2021 at 13:50
  • Hmm... It is difficult to customize the reference and subref formats if the label is set this way.
    – Tohiko
    Jun 30, 2021 at 14:17
  • 1
    I have to admit that redefining \thesubfigure is the simplest way to accomplish the task. The best part is that the effects are limited to one figure. Jul 1, 2021 at 1:53

0

You must log in to answer this question.

Browse other questions tagged .