Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I'm trying to sort figures (using subfloat) in a table, with labels for each subfigure. My point is, using only subfloat, that the subfigures are referred in the text as figure a, b, ... and so on. But I'd like to sort them in column too, so that they will be referred as 1a, 1b, 1c, 2a, 2b, ...

Is there a way to do that using the subfig package (through the subfloat command)? Or is there another package?

EDIT: The solution does not completely do what I would like ... Here is some precision. I would like to have two kind of figures: the one where each subfloat is different, and has its own "number", and the one where subfloats have to be sorted by column and row.

Here is an example based on the first answer:

\documentclass{article}
\usepackage[margin=1in]{geometry}
\usepackage[demo]{graphicx}
\usepackage{tabularx}
\usepackage[lofdepth,listofformat=parens]{subfig}
\usepackage{etoolbox}
\newcounter{subfigRow}
\makeatletter
\newcommand{\newRow}{\refstepcounter{subfigRow}\setcounter{sub\@captype}{0}}
\makeatother
\AtBeginEnvironment{figure}{\setcounter{subfigRow}{1}}
\DeclareCaptionLabelFormat{parens}{(\thesubfigRow#2)}
\DeclareSubrefFormat{parens}{(\thesubfigRow#2)}
\DeclareCaptionListOfFormat{parens}{(\thesubfigRow#2)}

\begin{document}
\listoffigures
\begin{figure}[htb]
\begin{tabular}{lccc}
1 &
\subfloat{\label{one}\includegraphics[width=.3\textwidth,height=.25in]{foo}} &
\subfloat{\label{two}\includegraphics[width=.3\textwidth,height=.25in]{foo}} &
\subfloat{\label{three}\includegraphics[width=.3\textwidth,height=.25in]{foo}}\\
\newRow
2 &
\subfloat{\label{four}\includegraphics[width=.3\textwidth,height=.25in]{foo}} &
\subfloat{\label{five}\includegraphics[width=.3\textwidth,height=.25in]{foo}} &
\subfloat{\label{six}\includegraphics[width=.3\textwidth,height=.25in]{foo}}\\
 & (a) & (b) & (c)
\end{tabular}
\caption{A bunch of figures}\label{fig:first}
\end{figure}

\begin{figure}[htb]
\subfloat[A subcaption][A subcaption\label{seven}]
    {\includegraphics[width=.3\textwidth,height=.25in]{foo}}
\qquad
\subfloat[A subcaption][A subcaption\label{eight}]
    {\includegraphics[width=.3\textwidth,height=.25in]{foo}}
\qquad
\subfloat[A subcaption][A subcaption\label{nine}]
    {\includegraphics[width=.3\textwidth,height=.25in]{foo}}
\qquad
\subfloat[A subcaption][A subcaption\label{ten}]
    {\includegraphics[width=.3\textwidth,height=.25in]{foo}}
\qquad
\subfloat[A subcaption][A subcaption\label{11}]
    {\includegraphics[width=.3\textwidth,height=.25in]{foo}}
\qquad
\subfloat[A subcaption][A subcaption\label{12}]
    {\includegraphics[width=.3\textwidth,height=.25in]{foo}}
\qquad
\caption{Another bunch of figures}\label{fig:second}
\end{figure}
As seen in \subref{one} and \subref{six} of Figure~\ref{fig:first} and
\subref{eight} of Figure~\ref{fig:second}
\end{document}

that gives enter image description here

My point is to have the number removed in the second case.

share|improve this question
    
Specifically, what do you mean by "sort"? Do you want LaTeX to re-arrange the subfigures? –  Werner Jan 2 '12 at 16:56
    
Hi Werner! Thanks for the answer. No, by 'sorting', I mean that I want to be able to refer to a subfigure using its position in columns and rows. For now, the subfloat command allows me to have a letter assigned to each subfigure. I would like to have a number (in reference of the subfigure raw) and a letter (in reference of the column). –  Gnesson Jan 2 '12 at 17:10
add comment

3 Answers

Here's a way to do it semi-automatically. We define a new counter for the row number; each time you add a row of subfigures you use the \newRow command to increment the row counter and reset the subfigure counter. I've also added code to format the captions in the list of figures and the references to show how the whole thing would work together.

\documentclass{article}
\usepackage[margin=1in]{geometry}
\usepackage[demo]{graphicx}
\usepackage[lofdepth,listofformat=parens]{subfig}
\usepackage{etoolbox}
\newcounter{subfigRow}
\makeatletter
\newcommand{\newRow}{\refstepcounter{subfigRow}\setcounter{sub\@captype}{0}}
\makeatother
\AtBeginEnvironment{figure}{\setcounter{subfigRow}{1}}
\DeclareCaptionLabelFormat{parens}{(\thesubfigRow#2)}
\DeclareSubrefFormat{parens}{(\thesubfigRow#2)}
\DeclareCaptionListOfFormat{parens}{(\thesubfigRow#2)}

\begin{document}
\listoffigures
\begin{figure}[htb]
\subfloat[A subcaption][A subcaption\label{one}]
    {\includegraphics[width=.3\textwidth,height=.25in]{foo}}
\qquad
\subfloat[A subcaption][A subcaption\label{two}]
    {\includegraphics[width=.3\textwidth,height=.25in]{foo}}
\qquad
\subfloat[A subcaption][A subcaption\label{three}]
    {\includegraphics[width=.3\textwidth,height=.25in]{foo}}
\qquad

\newRow
\subfloat[A subcaption][A subcaption\label{four}]
    {\includegraphics[width=.3\textwidth,height=.25in]{foo}}
\qquad
\subfloat[A subcaption][A subcaption\label{five}]
    {\includegraphics[width=.3\textwidth,height=.25in]{foo}}
\qquad
\subfloat[A subcaption][A subcaption\label{six}]
    {\includegraphics[width=.3\textwidth,height=.25in]{foo}}
\qquad
\caption{A bunch of figures}\label{fig:first}
\end{figure}

\begin{figure}[htb]
\subfloat[A subcaption][A subcaption\label{seven}]
    {\includegraphics[width=.3\textwidth,height=.25in]{foo}}
\qquad
\subfloat[A subcaption][A subcaption\label{eight}]
    {\includegraphics[width=.3\textwidth,height=.25in]{foo}}
\qquad
\subfloat[A subcaption][A subcaption\label{nine}]
    {\includegraphics[width=.3\textwidth,height=.25in]{foo}}
\qquad
\newRow
\subfloat[A subcaption][A subcaption\label{ten}]
    {\includegraphics[width=.3\textwidth,height=.25in]{foo}}
\qquad
\subfloat[A subcaption][A subcaption\label{11}]
    {\includegraphics[width=.3\textwidth,height=.25in]{foo}}
\qquad
\subfloat[A subcaption][A subcaption\label{12}]
    {\includegraphics[width=.3\textwidth,height=.25in]{foo}}
\qquad
\caption{Another bunch of figures}\label{fig:second}
\end{figure}
As seen in \subref{one} and \subref{six} of Figure~\ref{fig:first} and
\subref{eight} of Figure~\ref{fig:second}
\end{document}

output of code

share|improve this answer
    
+1: I think this is what the OP wants. I don't envy anyone trying to read the document though... –  cmhughes Jan 2 '12 at 21:58
    
@cmhughes I agree; a sequential list is probably easier. But if the references are all quite local (as I've done them) and the subfigures aren't listed in the LoF, it may be not so bad. –  Alan Munn Jan 2 '12 at 22:01
    
@Alan Munn : Thanks! It is exactly what I was looking for. –  Gnesson Jan 3 '12 at 10:08
    
@Gnesson: I converted your answer into a comment, as it's not really an answer to the question. –  Stefan Kottwitz Jan 3 '12 at 10:12
    
@StefanKottwitz Thanks. I wasn't able to comment because of an account mix up. –  Gnesson Jan 3 '12 at 14:44
add comment

Is this the kind of thing you want?

screenshot

I have used the subcaption package, combined with minipages.

\documentclass{article}
\usepackage{subcaption}

\begin{document}

\begin{figure}
\begin{minipage}{.5\textwidth}
\begin{subfigure}{\textwidth}
\centering
    \rule{20pt}{30pt}
    \caption{}
    \label{fig:subfig1}
\end{subfigure}\\
\begin{subfigure}{\textwidth}
\centering
    \rule{20pt}{30pt}
    \caption{}
    \label{fig:subfig2}
\end{subfigure}
\caption{}
\end{minipage}%
\begin{minipage}{.5\textwidth}
\begin{subfigure}{\textwidth}
\centering
    \rule{20pt}{30pt}
    \caption{}
    \label{fig:subfig3}
\end{subfigure}\\
\begin{subfigure}{\textwidth}
\centering
    \rule{20pt}{30pt}
    \caption{}
    \label{fig:subfig4}
\end{subfigure}
\caption{}
\end{minipage}
\end{figure}

\ref{fig:subfig1}, \ref{fig:subfig2}, \ref{fig:subfig3}, \ref{fig:subfig4}

\end{document}
share|improve this answer
add comment
up vote 1 down vote accepted

Ok. I just needed to adapt the solution from @Alan Munn, and change some of the subfig package options. So here is the final solution:

\documentclass{article}
\usepackage[margin=1in]{geometry}
\usepackage[demo]{graphicx}
\usepackage{tabularx}
\usepackage[lofdepth, subrefformat=subparens]{subfig}
\usepackage{etoolbox}
\newcounter{subfigRow}
\makeatletter
\newcommand{\newRow}{\refstepcounter{subfigRow}\setcounter{sub\@captype}{0}}
\makeatother
\AtBeginEnvironment{figure}{\setcounter{subfigRow}{1}}

\DeclareSubrefFormat{subparens}{(\thesubfigRow#2)}


\begin{document}
\listoffigures
\begin{figure}[htb]
\begin{tabular}{lccc}
1 &
\subfloat{\label{one}\includegraphics[width=.3\textwidth,height=.25in]{foo}} &
\subfloat{\label{two}\includegraphics[width=.3\textwidth,height=.25in]{foo}} &
\subfloat{\label{three}\includegraphics[width=.3\textwidth,height=.25in]{foo}}\\
\newRow
2 &
\subfloat{\label{four}\includegraphics[width=.3\textwidth,height=.25in]{foo}} &
\subfloat{\label{five}\includegraphics[width=.3\textwidth,height=.25in]{foo}} &
\subfloat{\label{six}\includegraphics[width=.3\textwidth,height=.25in]{foo}}\\
 & (a) & (b) & (c)
\end{tabular}
\caption{A bunch of figures}\label{fig:first}
\end{figure}

\begin{figure}[htb]
\subfloat[A subcaption][A subcaption\label{seven}]
    {\includegraphics[width=.3\textwidth,height=.25in]{foo}}
\qquad
\subfloat[A subcaption][A subcaption\label{eight}]
    {\includegraphics[width=.3\textwidth,height=.25in]{foo}}
\qquad
\subfloat[A subcaption][A subcaption\label{nine}]
    {\includegraphics[width=.3\textwidth,height=.25in]{foo}}
\qquad
\subfloat[A subcaption][A subcaption\label{ten}]
    {\includegraphics[width=.3\textwidth,height=.25in]{foo}}
\qquad
\subfloat[A subcaption][A subcaption\label{11}]
    {\includegraphics[width=.3\textwidth,height=.25in]{foo}}
\qquad
\subfloat[A subcaption][A subcaption\label{12}]
    {\includegraphics[width=.3\textwidth,height=.25in]{foo}}
\qquad
\caption{Another bunch of figures}\label{fig:second}
\end{figure}
As seen in \subref*{one} and \subref*{six} of Figure~\ref{fig:first} and
\subref{eight} of Figure~\ref{fig:second}
\end{document}

And it gives enter image description here

Thanks for your input ;-)

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.