# Subfigure labelling for a single figure with REVTeX 4.2

Look at this piece of paper from an APS journal:

as you can see there is a single image (called figure 3) with already embedded the (a), (b), etc.. letters indicating different parts of the same figure. If you look above it you can see they are able to reference the single parts of the figure (e.g. fig. 3(b)), but how is possible to do that since they don't have subfigures? My guessing was they were using phantom captions from the subcaption package, but this is not possible since this latter is not compatible with REVTeX 4.2 (that is the standard document package for APS journals). My question is: how can I obtain the same result?

Here you can find a Minimal Working Example of my attempt:

\documentclass{revtex4-2}
\usepackage[demo]{graphicx}

\begin{document}
\begin{figure}
\centering
\includegraphics[width=\textwidth]{example-image-a}
\caption{Main caption here}
\label{fig:main}
\end{figure}

Suppose that figure \ref{fig:main} is already divided in part (a) and part (b). I want to reference part \ref{fig:main}a and part \ref{fig:main}b, but if I do like this only the number is \textit{clickable}, not the letter. Moreover I have to write manually the letter. A workaround I have found is \hyperref[fig:main]{\ref{fig:main}a}, but I am still not satisfied because I still have to write the letter manually.

\end{document}


• Hi and welcome here! As you can see, many users don't understand your question. As Zarko said, please add a minimal working example showing what you have tried so far, as well as a sketch (if possible) showing what you want. – user156344 Feb 12 '19 at 14:02
• @JouleV Hi, thank you for your welcome! Can you please point out what is exactly unclear in my question? I understand the usefulness of a minimal working example, but in this case it won't be very useful because I would just write an \includegraphics line and then ask you how can I reference something that is inside the image file. To be clearer my question is exactly the same as this one: tex.stackexchange.com/questions/100716/… but with the difference that I cannot use the proposed solution since I can't use the caption package. – Alessandro Zunino Feb 12 '19 at 14:08

Note that I only have REVTex4-1, I however assume the solution works also for REVTex4-2.

I achieved the results using a hacky tikz solution. We use tikz to draw over the original plot. As subcaption is not available for REVTex, we use an empty subfig.

We first make an environment:

\newenvironment{captivy}[1]{%SETUP
\begin{tikzpicture}[every node/.style={inner sep=0}]
\node[anchor=south west,inner sep=0] (image) at (0,0) {#1};
\begin{scope}[x={(image.south east)},y={(image.north west)}]
}%
{%TEARDOWN
\end{scope}%
\pgfresetboundingbox
\path[use as bounding box] (image.south west) rectangle (image.north east);
\end{tikzpicture}%
}


This includes our figure given as argument #1 on a tikz picture. The last two lines in tikzpicture are about the bounding box, that we don't create additional whitespace.

Next we create a command to creat captions within this environment:

\newcommand*{\oversubcaption}[3]{%
\draw (#1) node[fill=white,inner sep=0pt, opacity=0.2, above, yscale=1.1, xscale=1.1] {\phantom{(a)#2}};
\draw (#1) node[inner sep=0pt, above]{%
\subfloat[#2\label{#3}]{\phantom{(a)}}
%   % \subcaption{#2}\label{#3}
};
}


As we cannot use \subcaption, we replaced it by \subfloat. We put the empty image \phantom(a), and add the label argument #3. Addtionally we can provide a caption #2. The first argument #1 specifies the position of the caption and label. (The first line adds a transparent background, you can omit it if you don't like it.)

The rest of the document would then be

\documentclass{revtex4-1}
\usepackage{tikz}
\usepackage{graphicx}
\usepackage[caption=false]{subfig}

\begin{document}
\begin{figure}
\centering
\begin{captivy}{\includegraphics[width=.5\textwidth]{example-image-a}}
\oversubcaption{0.2, 0.9}{}{fig:suba}
\oversubcaption{0.7, 0.9}{}{fig:subb}
\end{captivy}
\caption{Main caption here}
\label{fig:main}
\end{figure}

Suppose that figure \ref{fig:main} is already divided in part \subref{fig:suba} and part \subref{fig:subb}.
I want to reference part \ref{fig:suba} and part \ref{fig:subb}, but if I do like this only the number is \textit{clickable}, not the letter.
Moreover I have to write manually the letter.
A workaround I have found is \hyperref[fig:main]{\ref{fig:main}a}, but I am still not satisfied because I still have to write the letter manually.

\end{document}


Here is an elegant solution I have found. It produces the output as in the example provided as the desired output.

\documentclass{revtex4-2}
\usepackage[demo]{graphicx}
\usepackage[capitalize]{cleveref}

% \usepackage{subcaption} % Incompatible with revtex4-2
\usepackage[caption=false]{subfig}
% Keep the parentheses like in \subref but allow to use cleveref
\captionsetup[subfigure]{subrefformat=simple,labelformat=simple,listofformat=subsimple}
\renewcommand\thesubfigure{(\alph{subfigure})}
% Allows referencing phantom subfigures, i.e. when (a), (b) are part of an
% image itself. Must be followed by \vspace{-2\baselineskip}
\newcommand{\phantomsubfloat}[1]{
{% apply caption setup only temporarily
\captionsetup[subfigure]{labelformat=empty}
\subfloat[][]{#1}
}%
}

\begin{document}
\begin{figure}
\centering
\includegraphics[width=\textwidth]{example-image-a}
% Keep above the caption to avoid messing up counters
\phantomsubfloat{\label{fig:main_spaced_a}}
\phantomsubfloat{\label{fig:main_spaced_b}}
\phantomsubfloat{\label{fig:main_spaced_c}}
\caption{
Using empty subfloat gets half the job done, but there is too much space between the image and the main caption
\label{fig:main_spaced}
}
\end{figure}

\begin{figure}
\centering
\includegraphics[width=\textwidth]{example-image-a}
% Keep above the caption to avoid messing up counters
\phantomsubfloat{\label{fig:main_a}}
\phantomsubfloat{\label{fig:main_b}}
\phantomsubfloat{\label{fig:main_c}}
\vspace{-2\baselineskip}% Remove extra line inserted by subfloat
\caption{
But it can be elegantly removed!
\label{fig:main}
}
\end{figure}

\begin{figure}
\includegraphics[width=\textwidth]{example-image-a}
% Keep above the caption to avoid messing up counters
\phantomsubfloat{\label{fig:justified_a}}
\phantomsubfloat{\label{fig:justified_b}}
\phantomsubfloat{\label{fig:justified_c}}
\vspace{-2\baselineskip}% Remove extra line inserted by subfloat
\caption{
If caption centering is not desired you will find issues when trying to use the caption or subcaption packages (as several other solutions propose). But this solution keeps things elegant.
\label{fig:justified}
}
\end{figure}

You can now simply reference~\cref{fig:main_a}. \Cref{fig:main_a,fig:main_b,fig:main_c} can all be referenced now.

\end{document}


Result:

\documentclass{revtex4-2}
\usepackage{tabularx}
\usepackage[labelformat=simple]{subcaption}
\renewcommand\thesubfigure{(\alph{subfigure})}
\usepackage{graphicx}

\begin{document}
\begin{figure}[htb]
\captionsetup[subfigure]{singlelinecheck=off}
\begin{tabularx}{\linewidth}{*{3}{X}}
\begin{subfigure}[b]{\linewidth}
\caption{}\label{subfig:a}
\includegraphics[width=\linewidth]{example-image-duck}
\end{subfigure}
&
\begin{subfigure}[b]{\linewidth}
\caption{}\label{subfig:b}
\includegraphics[width=\linewidth]{example-image-duck}
\end{subfigure}
&
\begin{subfigure}[b]{\linewidth}
\caption{}\label{subfig:b}
\includegraphics[width=\linewidth]{example-image-duck}
\end{subfigure}
\\
coordinate image & coordinate image & coordinate image   \\
type             & type             & type
\end{tabularx}
\caption{some long text}
\label{fig:a}
\end{figure}
see \ref{subfig:a}
\end{document}


gives

note: since you not provide mwe, i didn't bother with table looks. i focused only on your question. coloring and lines you can add yourself.

• HI Zarko, thank you for your effort, but I am afraid you have mistaken my question. 1st problem: you are using the subcaption package that is not compatible with REVTeX 4.2. 2nd problem: In your answer you are including 3 images and this is not what I want to do. I want to include just a single figure with (a), (b), etc. letters already typed in it and I want to reference them in the text. – Alessandro Zunino Feb 12 '19 at 13:51
• @AlessandroZunino, this happen if you not provide mwe :-( – Zarko Feb 12 '19 at 13:52
• @AlessandroZunino, in my answer i replace document class with article with revtex4-2. it works. – Zarko Feb 12 '19 at 14:07
• Thank you again, I know it works, but revtex4-2 creates troubles if used together with the caption package (i.e. captions are badly formatted) and simply your answer is not answering my question. As I pointed out in another comment my question is exactly the same as this one: tex.stackexchange.com/questions/100716/… but with the difference that I cannot use the proposed solution since I can't use the subcaption package. – Alessandro Zunino Feb 12 '19 at 14:11
• please again, provide a mwe which demonstrate your problems. i can't conform your claims. – Zarko Feb 12 '19 at 14:19