2

I have a big image containing several subfigures, each with its own single letter caption already overlayed.

I'd like to reference these subcaptions from the text. As far as I recall something like this was achieavable with subcaption and its phantom commands, but I'm not that sure they covered this particular case.

Is there a way to do it from memoir?

Here's a sample figure to better explain what I'd like to do

enter image description here

It's a single image that I'd prefer not to split. And I'd like to reference the subimages as they were separate figures.

EDIT Below what I'd do if I could use subcaption, unfortunately as soon as I load it in a document using memoir's own subfigures it messes up with all the caption handling and styling.

So the question remains, is there a way to do phantom subcaptions within memoir?

\documentclass{memoir}
\usepackage{subcaption}

\begin{document}
\begin{figure}[t]
  \centering
  \includegraphics{figure.png}
  \begingroup
  \phantomsubcaption
  \label{fig:somefiga}
  \phantomsubcaption
  \label{fig:somefigb}
  \phantomsubcaption
  \label{fig:somefigc}
  \phantomsubcaption
  \label{fig:somefigd}
  \endgroup
  \caption{some caption}
  \label{fig:somefig}
\end{figure}
\noindent Figure~\ref{fig:somefig} has four subfigures:
figure~\ref{fig:somefiga} is a nice fat rectangle, figure\ref{fig:somefigb}
looks good too. Figures~\ref{fig:somefigc}~and~\ref{fig:somefigd} could do
better.
\end{document}
  • Apparently your code is in \phantom - mode as well. It's invisible... – user31729 Jan 30 '18 at 11:43
  • haha, there is no code yet, as I don't have any idea about how to do what I'm asking :-) the code would be just a figure with a \includegraphics{bigimagewithsubfigures.png} – filippo Jan 30 '18 at 11:47
  • @ChristianHupfer see e.g. tex.stackexchange.com/questions/100716/… it's roughly the same issue, there they solve it including the figure twice, the second one hidden, and using \phantomsubcaption to create references. I'd like to do something like that within memoir – filippo Jan 30 '18 at 11:53
  • @ChristianHupfer added an example figure... – filippo Jan 30 '18 at 12:04
  • 1
2

AFAIU, this cannot be achieved with just native Memoir macros. My own quick-and-dirty (absolutely no warranty) solution was to introduce slightly modified versions of the original native macros (side-by-side diff):

\documentclass[a4paper,14pt]{memoir}
\usepackage{graphicx}
\usepackage{hyperref}
\hypersetup{
    colorlinks=true,
    linkcolor=blue,
    filecolor=magenta,      
    urlcolor=cyan,
}

\usepackage[all]{hypcap}

% =============== defining the \subcaptionphantom ===================================
\makeatletter
% \begin{macro}{\subcaptionphantom}
% \cs{subcaptionphantom}\oarg{list-entry}\marg{caption} is a hidden
% non-printed subcaption. Designed for the case if "(a)", "(b)" are
% already embedded in the figure itself. 
% Roughtly equivalent to \cs{phantomsubcaption} from the \Lpack{subcaption} package.
%
%    \begin{macrocode}
\newcommand{\subcaptionphantom}{%
  \bgroup    
    \let\label=\memsub@label
    \ifdonemaincaption\else
      \advance\csname c@\@captype\endcsname\@ne
    \fi
    \refstepcounter{sub\@captype}\@contkeep
    \@ifnextchar [%
      {\@memsubcapphantom{sub\@captype}}%
      {\@memsubcapphantom{sub\@captype}[\@empty]}}
%    \end{macrocode}
% \end{macro}

% \begin{macro}{\@memsubcapphantom}
% Quick-and-dirty analog of \Lpack{memoir} \cs{memsubcap}, adapted
% for use in \cs{subcaptionphantom}.
%    \begin{macrocode}
\long\def\@memsubcapphantom#1[#2]#3{%
  \@tempdima=\hsize
  \vskip\subfloatcapskip
  \ifx \@empty #2
    \@memsubcaptionphantom{#1}{#3}{#3}%
  \else
    \@memsubcaptionphantom{#1}{#2}{#3}%
  \fi
  \vskip\subfloatcapskip
  \egroup}
%    \end{macrocode}
% \end{macro}
%
%
% \begin{macro}{\@memsubcaptionphantom}
% Quick-and-dirty analog of \Lpack{memoir} \cs{memsubcaption}, adapted
% for use in \cs{memsubcapphantom}.
%    \begin{macrocode}
\newcommand{\@memsubcaptionphantom}[3]{%

  \ifx \relax#2\relax \else
    \bgroup
      \let\label\@gobble
      \let\protect\string
      \def\@memsubcaplabel{\@nameuse{@@the#1}}%
      \xdef\@memsubfigcaptionlist{%
        \@memsubfigcaptionlist,%
  {\protect\numberline{\@memsubcaplabel}\noexpand{\ignorespaces #2}}}%
    \egroup
  \fi
  \@makesubfloatcaptionphantom{\@nameuse{@the#1}}{#3}%
  }

%    \end{macrocode}
% \end{macro}

% \begin{macro}{\@makesubfloatcaptionphantom}
% Quick-and-dirty analog of \Lpack{memoir} \cs{makesubfloatcaption}, adapted
% for use in \cs{memsubcaptionphantom}.
%    \begin{macrocode}
\newcommand{\@makesubfloatcaptionphantom}[2]{%
  \setbox\@tempboxa\hbox{%
    \@subcapsize
    {\phantom{\@subcaplabelfont#1}}{\ignorespaces #2}\unskip}%
  \@tempdimb=-\subfloatcapmargin
  \multiply\@tempdimb\tw@
  \advance\@tempdimb\@tempdima
  \hb@xt@\@tempdima{%
    \hss
    \ifdim \wd\@tempboxa >\@tempdimb
      \phantom{\memsubfig@caption{#1}}{#2}%
    \else
      \if@shortsubcap
        \phantom{\memsubfig@caption{#1}}{#2}%
      \else
        \box\@tempboxa
      \fi
    \fi
    \hss}}
%    \end{macrocode}
% \end{macro}
\makeatother
% ===================================================================================

\newsubfloat{figure} % allows to use "subbottom"

\begin{document}


\begin{figure}
\centering

\hfill%
\begin{minipage}[b][][b]{0.6\linewidth}
\centering
    \subcaptionphantom{\label{sf:1}}
    \subcaptionphantom{\label{sf:2}}
    \framebox[\linewidth]{\textit{subfigure with embedded (a)}}
    \framebox[\linewidth]{\textit{subfigure with embedded (b)}}
\end{minipage}
\hfill%
\begin{minipage}{0.3\linewidth}
    \centering
    \subbottom[regular subfigure \label{sf:3}]%
    {\includegraphics[width=0.7\linewidth]{example-image}}
\end{minipage}


\caption{Figure with three subfigures\label{fig:1}}
\end{figure}        

Example refs:\newline
Full fig: \ref{fig:1}. \newline
Sub1: \subcaptionref{sf:1}, same as \ref{sf:1} (the hidden caption). \newline 
Sub2: \subcaptionref{sf:2}, same as \ref{sf:2} (the hidden caption).  \newline
Sub3: \subcaptionref{sf:3}, same as \ref{sf:3}. \newline



\clearpage
This text is here to add more space for scrolling.

\end{document}

Same in Overleaf. Result screenshot

  • Looks good to me, didn't have the chance to test it properly yet though. I wish this or something like this would be included in memoir sooner or later... let's hope @daleif is reading this ;-) – filippo Jan 7 at 22:01

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.