I build something that is a) a complete MWE and b) does what you want.
Now the labels are displayed like "1.a" and the letters are changed to small letters. If you want to change the formatting of the subfigimg labels change the \renewcommand*{\thesubfigs}
to your liking, note that this only changes the way the labels are displayed, not those inside the images, for that change the \alph{subfigs}
in the definition of \@subfigimg
.
The command \subfigimg
is available as a starred and an unstarred version. Use the starred version if you use \caption
in the figure environment prior to your \subfigimg
and the unstarred one else. This is necessary because we have to increase the c@figure
-counter temporarily in order to get correct labels if the \caption
is used after \subfigimg
.
If you don't need a label on a \subfigimg
just leave the last argument empty.
I added the possibility to change the position of the label with two additional arguments. They are to be inserted in between the 2 mandatory arguments. The first is inserted with <horizontal>
(so <>
as delimiters) and changes the horizontal offset, the second [vertical]
changes the vertical offset.
\documentclass[preview,border=4mm]{standalone}
\usepackage{graphicx}
\usepackage{xparse}
\newcounter{subfigs}[figure]
\renewcommand*{\thesubfigs}{\thefigure.\alph{subfigs}}
\makeatletter
\NewDocumentCommand{\subfigimg}{s O{} m D<>{10pt} O{2\baselineskip} m}{%
\IfBooleanTF{#1}%
{\@subfigimg{#2}{#3}{#6}{0}{#4}{#5}}%
{\@subfigimg{#2}{#3}{#6}{1}{#4}{#5}}%
}
\newcommand*{\@subfigimg}[6]{%
\bgroup%
\advance\c@figure by #4%
\refstepcounter{subfigs}%
\ifx\relax#3\relax\else%
\label{#3}%
\fi%
\setbox1=\hbox{\includegraphics[#1]{#2}}% Store image in box
\leavevmode\rlap{\usebox1}% Print image
\rlap{\hspace*{#5}\raisebox{\dimexpr\ht1-#6\relax}{(\alph{subfigs})}}% Print label
\phantom{\usebox1}% Insert appropriate spcing
\egroup%
}
\makeatother
\begin{document}
\begin{figure}
\centering
\begin{tabular}{p{0.5\linewidth}@{}p{0.5\linewidth}}
\subfigimg[width=\linewidth]{example-image-c}{fig:s11}
&
\subfigimg[width=\linewidth]{example-image-b}{fig:s12}
\end{tabular}
\caption{bla bla bla}
\label{fig:1}
\end{figure}
See subfigures \ref{fig:s11} and \ref{fig:s12} of figure~\ref{fig:1}
\begin{figure}
\centering
\caption{bla bla bla}
\label{fig:2}
\begin{tabular}{p{0.5\linewidth}@{}p{0.5\linewidth}}
\subfigimg*[width=\linewidth]{example-image-c}<20pt>[4\baselineskip]{fig:s21}
&
\subfigimg*[width=\linewidth]{example-image-b}{fig:s22}
\end{tabular}
\end{figure}
See subfigures \ref{fig:s21} and \ref{fig:s22} of figure~\ref{fig:2}
\end{document}
Note that the subfigs
counter is only reset after the figure counter is increased or when you manually reset it with something like \setcounter{subfigs}{0}
.
\documentclass{...}
and ending with `\end{document}.subcaption
orsubfig
package?