# label in subcaption and customize cell size of an array

Using the following code

\documentclass[11pt]{article}
\usepackage{caption}
\usepackage{subcaption}
\DeclareCaptionSubType*[arabic]{table}
\captionsetup[subtable]{labelformat=simple,labelsep=space}

\begin{document}

\begin{table}[ht]
\begin{subtable}{.5\textwidth}
\centering
$\begin{array}{ | c | c | c | c | } \hline \ast & \ast & \ast & \ast \\ \hline \ast & \ast & \ast & \ast \\ \hline \ast & \ast & \ast & \ast \\ \hline \ast & \ast & \ast & \ast \\ \hline \end{array}$
\subcaption{Subtable 1}
\label{lab1}
\end{subtable}
\begin{subtable}{.5\textwidth}
\centering
$\begin{array}{ | c | c | c | c | } \hline \ast & \ast & \ast & \ast \\ \hline \ast & \ast & \ast & \ast \\ \hline \ast & \ast & \ast & \ast \\ \hline \ast & \ast & \ast & \ast \\ \hline \end{array}$
\subcaption{Subtable 1}
\label{lab2}
\end{subtable}
\caption{Sub Tables}
\label{lab3}
\end{table}

\end{document}


I can produce the below table and subtables. One question is how to use 1a, 1b as label (counter?), instead of 1.1, 1.2.

The second question is how to customize the cell size in an array? In the above example, each cell is an exact square, but if I type something inside, it become (not exact ) rectangle automatically. One can use \begin{array}{ | p{1cm} | p{1cm} | } to fix the cell width to 1cm, but I didn't find a way to fix cell height. Also, even one can fix the size, how to put the content in the center?

Final question is how to put a diagonal line or a cross in a cell? (I found a way which use TikZ, but if there is eaiser way? )

-
I searched for a while, it seems there is no direct way to assign the row height, like p{width} or m{width}. I can't believe it..... – user565739 Nov 24 '11 at 14:59
Regarding the 1st question \renewcommand\thesubtable{\thetable\alph{subtable}} should do the job. Please also take a look at the section "References" I have added to the very recent version of the subcaption package documentation. – Axel Sommerfeldt Nov 24 '11 at 15:21
@Axel, thank you very much!! – user565739 Nov 24 '11 at 15:45

You asked quite a few questions, and I'll try and answer them in order.

1. To change the sub-table labels, you can use

\DeclareCaptionSubType*[alph]{table}

2. There are quite a few ways to change the vertical sizing of an array; if you load the array package, then you can use

\renewcommand{\arraystretch}{2}


and change the 2 to whatever you would like. Alternatively you could use something like the bigstrut package, which provides the command \bigstrut to be used at the end of each line. You could also use something like \parbox[c][3cm][t]{3cm}{ ...content...} which would guarantee the cell size.

3. Finally, have a look at the following post to put a diagonal line in a table cell

Diagonal lines in table cell

A complete MWE follows

\documentclass[11pt]{article}
\usepackage{caption}
\usepackage{subcaption}
\DeclareCaptionSubType*[alph]{table}
\captionsetup[subtable]{labelformat=simple,labelsep=space}
\usepackage{array}
\usepackage{bigstrut}

\begin{document}

\begin{table}[ht]
\begin{subtable}{.5\textwidth}
\centering
$\begin{array}{ | c | c | c | c | } \hline \parbox[c][3cm][b]{3cm}{$\ast$} & \ast & \ast & \ast \bigstrut\\ \hline \ast & \ast & \ast & \ast \\ \hline \ast & \ast & \ast & \ast \\ \hline \ast & \ast & \ast & \ast \\ \hline \end{array}$
\subcaption{Subtable 1}
\label{lab1}
\end{subtable}
\begin{subtable}{.5\textwidth}
\centering
\renewcommand{\arraystretch}{2}
$\begin{array}{ | c | c | c | c | } \hline \ast & \ast & \ast & \ast \\ \hline \ast & \ast & \ast & \ast \\ \hline \ast & \ast & \ast & \ast \\ \hline \ast & \ast & \ast & \ast \\ \hline \end{array}$
\subcaption{Subtable 1}
\label{lab2}
\end{subtable}
\caption{Sub Tables}
\label{lab3}
\end{table}

\end{document}


Following the comment, you could define a \newcommand

\newcommand{\mycell}[1]{\parbox[c][3cm][c]{3cm}{\centering #1}}


which can be used as (for example)

 \mycell{$\ast$}


and will center the contents vertically and horizontally

-
thanks. But I found neither the ways are good. Why there is no direct way to assign the row height? For column width, we can use p{width} to do this. Using \arraystretch and \bigstrut, we need to adjust several times to get equal width and height. Furthermore, if I use 'c' to center the content, after using \arraystretch it's no longer at the center. – user565739 Nov 24 '11 at 16:35
@user565739 see my edited answer (MWE updated too) – cmhughes Nov 24 '11 at 16:43
thanks again. I like this way since in \parbox, one can type whatever he wants, although I have to type many \parbox if I need it for each entry in my array. Do you know how to put thing in the center in a \parbox? For example, in \parbox[c][1cm][c]{1cm}{ $\ast$ }, the \ast is not at the center. Or if I want to put 123, then it's not at the center neither. I could get vertical center, but not horizontal center. (But if I use $\ast$ inside \parbox, I got horizontal center but not vertical center.....sigh) – user565739 Nov 24 '11 at 17:29
@user565739 see my edit – cmhughes Nov 24 '11 at 19:25
Thanks, it works very well!!!! – user565739 Nov 24 '11 at 22:19