Hmm... seems I prematurely declared victory earlier
First, there is a problem with the labels - the generated ones are a, c, e - b and d are skipped; the
subcaption.pdf says: "The star variant is neither incrementing the sub-caption counter nor setting an hyperref anchor.", and that solves the matter.
The other thing is, the earlier code uses \usepackage[rel]{overpic}; but in order to align the boxes properly for all three images, \usepackage[abs]{overpic} should be used; and then the placement coordinates should be calculated for each image according to its width. While the width can be obtained pretty easily, it is in fact a string with "pt" at the end, which \put crashes on. So, now we basically have to take a substring in Latex, which seems not the easiest thing to do, but there is this "catcode" trick from
LaTeX Community • View topic - How to print out the value of \textwidth? which helped.
Those changes taken into account, the code is below.
Well, hope there are no further 'big' bugs with this,
Cheers!
Code: Select all
\usepackage{color} %enables text in color: \textcolor
% subfig and subcaption conflict!
\usepackage[font=footnotesize,labelfont=bf]{caption} %many ways to customise the captions - text justification
\usepackage{subcaption} % so we can modify subcaptions - understands subfloat command
%\usepackage[caption=false]{subfig} %subfigure is deprecated, use subfig (which is not backwards compatible). Must be included after caption. But even "[subcaption] package is a part of caption and represents some kind of replacement for subfig, which seems not to be maintained anymore."
%\usepackage{subfigure} %provides support for the inclusion of small, 'sub'- figures and tables.
\usepackage[abs]{overpic} % Combine LaTeX commands over included graphics. Use abs instead of percent, then can scale via \textwidth
% corner image label
\definecolor{cornerlabelbckgcol}{gray}{0.8}
% http://74.125.77.132/search?q=cache:X7wj_-tm-NUJ:www.lncc.br/~jmsilva/pdf/caption-eng.pdf
\DeclareCaptionLabelFormat{cornerlabelbckg}{\colorbox{cornerlabelbckgcol}{(\textsl{#2})}}
%
% for proper calc of position of corner image label with [abs]{overpic}:
% this catcode trick can erase "pt" at end of textwidth
% http://www.latex-community.org/forum/viewtopic.php?f=5&t=2712
% since it erases "p" and "t", the defname (here ersz) cannot contain "p" nor "t"!
% (else would've called it 'erspt')
{\catcode`p=12 \catcode`t=12 \gdef\ersz#1pt{#1}}
\newcommand{\textwidthplain}{\expandafter\ersz\the\textwidth } %textwidth without 'pt' on end
% so can use, to store only number without pt: \renewcommand{\textwidthplain}{\expandafter\ers\the\textwidth }
% and to printout: \textwidthplain - \the\textwidth ... or \message{HERE IS \textwidthplain}
\newlength{\cornerw} % variable for placement of cornel label (used for xput)
\newlength{\cornerh} % variable for placement of cornel label (used for yput)
\newlength{\cornerleft} % variable for placement of cornel label (used for xput)
\begin{document}
\newsavebox{\lefttempbox}
% \put expects "pure" numbers - will crash if there is "pt" on end...
\newcommand{\xput}{90}
\newcommand{\yput}{20}
\setlength{\cornerleft}{-1.85em}
\begin{figure}%
\centering % no centering, else images will not be next to each other, but ...
\begin{minipage}[t]{0.9\textwidth} % ... add one more minipage to have all images centered
% this works for color background of label only
\captionsetup[subfloat]{labelformat=cornerlabelbckg,labelsep=quad}
% renew yput here after captionsetup, so char size is correct
% all three images will use it the same
\setlength{\cornerh}{1.5\baselineskip}
\renewcommand{\yput}{\expandafter\ersz\the\cornerh }
\setlength{\cornerw}{0.55\textwidth} % set to scaled width
% this savebox will specify height of the whole figure
\sbox{\lefttempbox}{%
\begin{overpic}[grid,width=\cornerw,unit=1pt]{img001.png}
\addtolength{\cornerw}{\cornerleft} % go back left, leave space for the character
\renewcommand{\xput}{\expandafter\ersz\the\cornerw } % get myw as number only
\put(\xput,\yput){\subcaptionbox{\label{fig:ex3-a}}}
\end{overpic}}%
% add the saved box as leftmost image
% do not call \subfloat[][] when using subcaption and \subcaptionbox - sublabels will be included twice!
% but - although they are not shown, they are still skipped (i.e. am getting a,c,e)
% so, use: "The star variant is neither incrementing the sub-caption counter nor setting an hyperref anchor."
\subfloat*{\usebox{\lefttempbox}}% % subfloat caption actually determined here!
\qquad % leave some horizontal space
%
\setlength{\cornerw}{0.35\textwidth} % set to scaled width
% add minipage too, to control vertical alignment. fixes width too - so images can refer to \textwidth
\begin{minipage}[t]{\cornerw}
\vbox to \ht\lefttempbox{%
% overpics don't use myw here, so ok to subtract immediately
\addtolength{\cornerw}{\cornerleft} % go back left, leave space for the character
\renewcommand{\xput}{\expandafter\ersz\the\cornerw } % get myw as number only
%
% add top image - test without overpic - coordinates of put are different here
\subfloat*{%
\begin{overpic}[grid,width=\textwidth,unit=1pt]{img002.png}
\put(\xput,\yput){\subcaptionbox{\label{fig:ex3-b}}}
\end{overpic}
}%
%
\vfil % leave vertical space
%
% add bottom image
\subfloat*{%
\begin{overpic}[grid,width=\textwidth,unit=1pt]{img003.png}
\put(\xput,\yput){\subcaptionbox{\label{fig:ex3-c}}}
\end{overpic}
}%
} % end vbox
\end{minipage}
%
\end{minipage}
%
\clearcaptionsetup[subfloat]{} % {figure}, cannot do [subfloat]
\caption{Three more sub-floats: \subref{fig:ex3-a} , \subref{fig:ex3-b}, \subref{fig:ex3-c} }
\label{fig:ex3}
\end{figure}
Continue text...
% some debug messages
%\message{HERE IS \the\textwidth} %"134.4407pt"
%\message{HERE IS \uselengthunit{PT} \printlength{\textwidth}} %\usepackage{printlen}
%\message{HERE IS \printinunitsof{cm}\prntlen{\textwidth} } %\usepackage{layouts}
%\renewcommand{\textwidthplain}{\expandafter\ersz\the\textwidth }
%\message{HERE IS \textwidthplain}
\end{document}