在子标题中标记并自定义数组的单元格大小

在子标题中标记并自定义数组的单元格大小

使用以下代码

\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}

我可以生成下表和子表。一个问题是如何使用 1a、1b 作为标签(计数器?),而不是 1.1、1.2。图片

第二个问题是如何自定义数组中的单元格大小?在上面的例子中,每个单元格都是一个精确的正方形,但如果我在里面输入一些内容,它就会自动变成(不是精确的)矩形。可以使用\begin{array}{ | p{1cm} | p{1cm} | }将单元格宽度固定为 1cm,但我没有找到固定单元格高度的方法。此外,即使可以固定大小,如何将内容放在中心?

最后一个问题是如何在单元格中画对角线或十字?(我发现了一种使用 TikZ 的方法,但是有没有更简单的方法呢?)

答案1

你问了不少问题,我会尽量按顺序回答。

  1. 要更改子表标签,您可以使用

    \DeclareCaptionSubType*[alph]{table}
    
  2. 有很多方法可以改变的垂直尺寸array;如果你加载array包,那么你可以使用

    \renewcommand{\arraystretch}{2}
    

    并将 更改2为您想要的任何内容。或者,您可以使用类似包的东西,它提供了要在每行末尾使用的bigstrut命令。您还可以使用类似的东西,这将保证单元格大小。\bigstrut\parbox[c][3cm][t]{3cm}{ ...content...}

  3. 最后,看看下面的文章,在表格单元格中放置对角线

    表格单元格中的对角线

完整的 MWE 如下

\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}

根据评论,你可以定义一个\newcommand

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

可以用作(例如)

 \mycell{$\ast$}

并将内容垂直和水平居中

相关内容