4

I'm currently writing an assignment report using Latex and I'm having some trouble when cross-referencing to "fake" sub-pictures.

When I say fake it's because I'm importing a single picture drawn in Inkscape merging 4 different sub-figures like this enter image description here

I want to be able when I pass \cref{fig:model} I can reference to (Figure 1A) or (Figure 1B)

Here is my MWE:

\usepackage{graphicx}
\usepackage[round]{natbib}
\usepackage{hyperref} 
\usepackage{cleveref}
\crefformat{figure}{#2(\figurename~#1)#3}
 
\documentclass[notitlepage, 12pt]{report}


\begin{document}

\begin{figure}[h]
    \centering
    \includegraphics[height=10cm,width=16cm]{imagens/model.png}
    \caption{caption}
    \label{fig:model}
\end{figure}


\bibliography{ref}{}
\bibliographystyle{geo-apalike}

\end{document}

I'm using a different format in cref as explained in here: Place parentheses around a cross-reference for Figure

Any suggestion on how to do this?

2 Answers 2

5

This draws on Mico's answer, but also sets the anchors (approximately) at the right points: if you click on the links, you get moved to the proper subfigure.

The idea is to produce four empty subfigure environments that take the same space as the subfigures (the “approximate” refers to the small gap between the images, but it should not be a big concern). After these empty environments, the image is printed, but taking no vertical space, so it will exactly cover the previous space.

\documentclass{article}
\usepackage{graphicx,subcaption}
\usepackage{hyperref} 
\usepackage{cleveref}

\crefformat{figure}{#2(\figurename~#1)#3}
\newsavebox{\fourfigurebox}

\begin{document}

\cref{four:a},
\cref{four:b},
\cref{four:c},
\cref{four:d},
\cref{four}.

\begin{figure}[htp]
\sbox\fourfigurebox{\includegraphics[width=\textwidth]{fourimages}}% change with your own image

\begin{subfigure}[t][0.5\ht\fourfigurebox]{0.5\textwidth}
\refstepcounter{subfigure}\label{four:a}
\end{subfigure}%<---- Don't forget
\begin{subfigure}[t][0.5\ht\fourfigurebox]{0.5\textwidth}
\refstepcounter{subfigure}\label{four:b}
\end{subfigure}\par\nointerlineskip
\begin{subfigure}[t][0.5\ht\fourfigurebox]{0.5\textwidth}
\refstepcounter{subfigure}\label{four:c}
\end{subfigure}%<---- Don't forget
\begin{subfigure}[t][0.5\ht\fourfigurebox]{0.5\textwidth}
\refstepcounter{subfigure}\label{four:d}
\end{subfigure}\par\nointerlineskip
\smash{\usebox{\fourfigurebox}}

\caption{These are four images}\label{four}

\end{figure}

\end{document}

enter image description here

1
  • Thank you @egreg! Your solution was very clean and helped me a lot!
    – raulindo
    Jul 8, 2020 at 23:19
7

I suppose you could insert a dummy subfigure environment, containing no graphs but just four \refstepcounter and \label directives, inside the figure environment to create four implicit (but invisible) subfigures.

That said, I can see nothing wrong in just writing "As shown in Panels A and B of \cref{fig:model}, ..."

enter image description here

\documentclass[notitlepage, 12pt, demo]{report} % omit 'demo' option in real document
\usepackage{graphicx,subcaption}
\renewcommand\thesubfigure{\Alph{subfigure}} % OP wants uppercase letters

\usepackage[colorlinks,allcolors=blue]{hyperref} 
\usepackage[noabbrev,nameinlink]{cleveref}
\crefformat{figure}{#2(\figurename~#1)#3}
 
\begin{document}

\begin{figure}[h]
\begin{subfigure}{1\textwidth} % this 'subfigure' env. has no visible content
    \refstepcounter{subfigure}\label{fig:model:a}
    \refstepcounter{subfigure}\label{fig:model:b}
    \refstepcounter{subfigure}\label{fig:model:c}
    \refstepcounter{subfigure}\label{fig:model:d}
\end{subfigure}%
\includegraphics[width=\textwidth]{imagens/model.png}
\caption{A figure with four implicit subfigures}
\label{fig:model}
\end{figure}

As shown in \cref{fig:model:a} and \cref{fig:model:b}, \dots

As shown in Panels A and B of \cref{fig:model}, \dots
\end{document}
1
  • 2
    Thanks @Mico. It worked just fine!!
    – raulindo
    Jul 8, 2020 at 23:18

You must log in to answer this question.

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