diff --git a/elasticrow.sty b/elasticrow.sty
index dc413c0..e7ca0fe 100644
--- a/elasticrow.sty
+++ b/elasticrow.sty
@@ -20,10 +20,13 @@
\newlength{\elasticrow@sep}
\newsavebox{\elasticrow@box}
\newtoks{\elasticbox@argtoks}
+\newcommand{\elasticfigure@caption}
+\newcommand{\elasticfigure@label}
\newif\ifelasticrow@fullwidth
%% command for adding figures to the row
-% syntax: \elasticfigure[
]{}
+% syntax: \elasticfigure[]{},
+% where use a key-value syntax with keys 'caption' and 'label'
\newcommand{\elasticfigure}[2][\empty]{%
\elasticbox@argtoks=\expandafter{\the\elasticbox@argtoks\elasticfun[#1]{#2}}%
}
@@ -31,6 +34,9 @@
%% keys for the elasticrow environment
\define@key{elasticrow@key}{width}{\setlength{\elasticrow@width}{#1}}
\define@key{elasticrow@key}{sep}{\def\elasticrow@whitespace{#1}}
+%% keys for the elasticfigure command
+\define@key{elasticfigure@key}{caption}{\def\elasticfigure@caption{#1}}
+\define@key{elasticfigure@key}{label}{\def\elasticfigure@label{#1}}
%% environment for the elastic row
% syntax: \begin{elasticrow}[],
@@ -39,7 +45,6 @@
\setlength{\elasticrow@width}{\elasticrowwidth}%
\def\elasticrow@whitespace{\elasticrowsep}%
\setkeys{elasticrow@key}{#1}%
- \ifdimequal{\elasticrow@width}{\textwidth}{\elasticrow@fullwidthtrue}{\elasticrow@fullwidthfalse}%
\elasticbox@argtoks={}%
}{%
\addtolength{\elasticrow@width}{\elasticrow@whitespace}%
@@ -61,7 +66,9 @@
\ifx#1\empty%
\includegraphics[height=\elasticrow@height]{#2}%
\else%
- \subcaptionbox{#1}{\includegraphics[height=\elasticrow@height]{#2}}%
+ % Set the provided key-value pairs
+ \setkeys{elasticfigure@key}{#1}%
+ \subcaptionbox{\elasticfigure@caption\label{\elasticfigure@label}}{\includegraphics[height=\elasticrow@height]{#2}}%
\fi%
% set \elasticrow@sep for the next figures
% - uses \fill for full-width rows, to prevent line break due to minor width overflow
diff --git a/elasticrow.tex b/elasticrow.tex
index 253f449..4ef58e3 100644
--- a/elasticrow.tex
+++ b/elasticrow.tex
@@ -27,10 +27,17 @@ \section{Usage}
\begin{figure}[!h]
\centering
\begin{elasticrow}[width=0.75\linewidth, sep=1em]
- \elasticfigure[Figure with an A]{example-image-a}
- \elasticfigure[A 16x9 figure]{example-image-16x9}
+ \elasticfigure[
+ caption=Figure with an A,
+ label=fig:subfig1
+ ]{example-image-a}
+ \elasticfigure[
+ caption=A 16x9 figure,
+ label=fig:subfig2
+ ]{example-image-16x9}
\end{elasticrow}
\caption{Caption of the surrounding \texttt{figure} environment}
+ \label{fig:fig1}
\end{figure}
\noindent
@@ -39,13 +46,20 @@ \section{Usage}
\begin{figure}[!h]
\centering
\begin{elasticrow}[width=0.75\linewidth, sep=1em]
- \elasticfigure[Figure with an A]{example-image-a}
- \elasticfigure[A 16x9 figure]{example-image-16x9}
+ \elasticfigure[
+ caption=Figure with an A,
+ label=fig:subfig1
+ ]{example-image-a}
+ \elasticfigure[
+ caption=A 16x9 figure,
+ label=fig:subfig2
+ ]{example-image-16x9}
\end{elasticrow}
\caption{Caption of the surrounding \texttt{figure} environment}
\end{figure}
\end{verbatim}
+, where each subfigure can be individually referenced with \verb*|Fig.~\ref{fig:subfig1}|, \verb*|Fig.~\ref{fig:subfig2}|, and \verb*|Fig.~\ref{fig:sub1}|, rendered as Fig.~\ref{fig:subfig1}, Fig.~\ref{fig:subfig2}, and Fig.~\ref{fig:fig1}.
\subsection{Control parameters}