\subfloat command from subcaption package doesn't produce bottom margin if used in table

I'm trying to typeset a table of images. If image inserted into cell with \subfloat (subcaption package included), resulting box will be w/o bottom margin, but top, left and right margins will be ok.

Example:

\documentclass[a4paper]{book}
\usepackage[utf8]{inputenc}
\usepackage[demo]{graphicx}
\usepackage{caption}
\usepackage{subcaption}

\begin{document}

\chapter{Sample Chapter}

\begin{table}
\caption{Sample Table}
\label{tbl:sample}
\begin{tabular}{|c|c|c|}
\hline
\begin{tabular}{c} \subfloat{\includegraphics[width=0.15\linewidth,height=0.15\linewidth]{image1}} \end{tabular} &
\begin{tabular}{c} \subfloat{\includegraphics[width=0.15\linewidth,height=0.15\linewidth]{image1}} \end{tabular} &
\begin{tabular}{c} \subfloat{\includegraphics[width=0.15\linewidth,height=0.15\linewidth]{image1}} \end{tabular}
\\\hline
\begin{tabular}{c} \subfloat{\includegraphics[width=0.15\linewidth,height=0.15\linewidth]{image2}} \end{tabular} &
\begin{tabular}{c} \subfloat{\includegraphics[width=0.15\linewidth,height=0.15\linewidth]{image2}} \end{tabular} &
\begin{tabular}{c} \subfloat{\includegraphics[width=0.15\linewidth,height=0.15\linewidth]{image2}} \end{tabular}
\\\hline
\end{tabular}
\end{table}

\end{document}


If subcaption package replaced with subfig the table looks good.

Is there any way to fix such behavior, since I can't use subfig? Or maybe there is another way to do table with images?

Update: Thanks to Gonzalo Medina, I solved original problem. But I stuck with another one with that approach. I'm trying to put titles in separate column:

\documentclass[a4paper]{book}
\usepackage[demo]{graphicx}
\usepackage{caption}

\begin{document}

\begin{table}
\centering
\caption{Sample Table}
\label{tbl:sample1}
\renewcommand\arraystretch{2}
\begin{tabular}{|c|c|c|c|}
\hline\rule{0pt}{\dimexpr0.15\textwidth+1em\relax}

imeage 1 &
\includegraphics[width=0.15\textwidth,height=0.15\textwidth]{image1} &
\includegraphics[width=0.15\textwidth,height=0.15\textwidth]{image1} &
\includegraphics[width=0.15\textwidth,height=0.15\textwidth]{image1}

\\\hline\rule{0pt}{\dimexpr0.15\textwidth+1em\relax}

imeage 2 &
\includegraphics[width=0.15\linewidth,height=0.15\linewidth]{image2} &
\includegraphics[width=0.15\linewidth,height=0.15\linewidth]{image2} &
\includegraphics[width=0.15\linewidth,height=0.15\linewidth]{image2}

\\ \hline
\end{tabular}
\end{table}

\end{document}


But text in first column is aligned at bottom of cell. How to make text in title column to be centered?

-
Apparently your subfloats won't have a caption. Is this the case? –  Gonzalo Medina Sep 19 '11 at 20:05
yes, subfloats must be w/o a caption. –  TheBug Sep 19 '11 at 20:12

\subfloat is not a command implemented in the subcaption package, so it won't be recognised by the package. If you want to use the subcaption package, you can use the either the subtable environment or the \subcaptionbox command. If your subimages don't need a caption, you can simply use \includegraphics.

In the following example I used the tabu package to buid the table with the six images. In the first case, the images won't have a caption: in the second case, each image will have its caption:

\documentclass[a4paper]{book}
\usepackage[demo]{graphicx}
\usepackage{caption}
\usepackage{subcaption}
\usepackage{tabu}

\begin{document}

\begin{table}
\centering
\caption{Sample Table}
\label{tbl:sample1}
\tabulinesep =_1em^1em
\everyrow{\tabucline[0.4pt]-}
\begin{tabu}{|c|c|c|}
\includegraphics[width=0.15\textwidth,height=0.15\textwidth]{image1} &
\includegraphics[width=0.15\textwidth,height=0.15\textwidth]{image1} &
\includegraphics[width=0.15\textwidth,height=0.15\textwidth]{image1}
\\
\includegraphics[width=0.15\linewidth,height=0.15\linewidth]{image2}  &
\includegraphics[width=0.15\linewidth,height=0.15\linewidth]{image2} &
\includegraphics[width=0.15\linewidth,height=0.15\linewidth]{image2}
\end{tabu}
\end{table}

\begin{table}
\centering
\caption{Sample Table}
\label{tbl:sample2}
\tabulinesep =_1em^0.5em
\everyrow{\tabucline[0.4pt]-}
\begin{tabu}{|c|c|c|}
\subcaptionbox{text}{\includegraphics[width=0.15\textwidth,height=0.15\textwidth]{image1}} &
\subcaptionbox{text}{\includegraphics[width=0.15\textwidth,height=0.15\textwidth]{image1}} &
\subcaptionbox{text}{\includegraphics[width=0.15\textwidth,height=0.15\textwidth]{image1}}
\\
\subcaptionbox{text}{\includegraphics[width=0.15\linewidth,height=0.15\linewidth]{image2}}  &
\subcaptionbox{text}{\includegraphics[width=0.15\linewidth,height=0.15\linewidth]{image2}} &
\subcaptionbox{text}{\includegraphics[width=0.15\linewidth,height=0.15\linewidth]{image2}}
\end{tabu}
\end{table}

\end{document}


Without the tabu package, in order to achieve the same result, some manual adjustments will be needed:

\documentclass[a4paper]{book}
\usepackage[demo]{graphicx}
\usepackage{caption}
\usepackage{subcaption}

\begin{document}

\begin{table}
\centering
\caption{Sample Table}
\label{tbl:sample1}
\renewcommand\arraystretch{2}
\begin{tabular}{|c|c|c|}
\hline\rule{0pt}{\dimexpr0.15\textwidth+1em\relax}
\includegraphics[width=0.15\textwidth,height=0.15\textwidth]{image1} &
\includegraphics[width=0.15\textwidth,height=0.15\textwidth]{image1} &
\includegraphics[width=0.15\textwidth,height=0.15\textwidth]{image1}
\\ \hline\rule{0pt}{\dimexpr0.15\textwidth+1em\relax}
\includegraphics[width=0.15\linewidth,height=0.15\linewidth]{image2}  &
\includegraphics[width=0.15\linewidth,height=0.15\linewidth]{image2} &
\includegraphics[width=0.15\linewidth,height=0.15\linewidth]{image2}
\\ \hline
\end{tabular}
\end{table}

\begin{table}
\centering
\caption{Sample Table}
\label{tbl:sample2}
\begin{tabular}{|c|c|c|}
\hline\rule{0pt}{23pt}
\subcaptionbox{text}{\includegraphics[width=0.15\textwidth,height=0.15\textwidth]{image1}} &
\subcaptionbox{text}{\includegraphics[width=0.15\textwidth,height=0.15\textwidth]{image1}} &
\subcaptionbox{text}{\includegraphics[width=0.15\textwidth,height=0.15\textwidth]{image1}}
\\[5.5em] \hline\rule{0pt}{23pt}
\subcaptionbox{text}{\includegraphics[width=0.15\linewidth,height=0.15\linewidth]{image2}}  &
\subcaptionbox{text}{\includegraphics[width=0.15\linewidth,height=0.15\linewidth]{image2}} &
\subcaptionbox{text}{\includegraphics[width=0.15\linewidth,height=0.15\linewidth]{image2}}
\\[5.5em] \hline
\end{tabular}
\end{table}

\end{document}

-
You said: "\subfloat is not a command implemented in the subcaption package". But if I remove \usepackage{subcaption} command I'll get compilation error Undefined control sequence at '\subfloat' command. So it seems that subcaption package defines '\subfloat' command. Or it just uses another package that defines that command? –  TheBug Sep 19 '11 at 20:36
@TheBug \subfloat is not defined in subcaption; it is defined in the subfig package which is incompatible with subcaption. –  Gonzalo Medina Sep 19 '11 at 20:40
I'm sorry, maybe I wrote my question not so clear. Code in question use only four packages: inputenc, graphicx, caption and subcaption. As you see subfig is not included. Which one of these four packages does introduce \subfloat command? –  TheBug Sep 19 '11 at 21:18
@TheBug: none. Compiling your example code in my system (TeX Live2011) produces the error ! Undefined control sequence. l.16 \begin{tabular}{c} \subfloat {\includegraphics[width=0.15\linewidth,.... Do you get something different? –  Gonzalo Medina Sep 19 '11 at 21:20
Interesting... Code above compiled fine on my system. I'm using TeX Live 2009 (standard texlive package on Ubuntu 10.10). What version of caption and subcaption packages do you use? –  TheBug Sep 19 '11 at 21:28