表格中某个单元格居中 + 拆分单元格

表格中某个单元格居中 + 拆分单元格

我想得到一个列联表,但我有两个问题
* 首先,我想拆分我的列名。我尝试过(如下所示)使用 \,但没有成功
* 我想将包含“a”、“b”、“c”和“d”的单元格居中。我尝试过使用多列对“a”进行拆分,但没有成功

\begin{table}[h]
 \centering
 \scriptsize
\begin{tabular}{|m{4.8cm}|m{4.8cm}|m{4.8cm}|}
    \hline
           &  \textbf{Classified as a keyword\\ by the human} & \textbf{Classified as not a\\ keyword by the human} \\ \hline
            \textbf{Classified as a keyword by the automatic extraction} & \multicolumn{1}{|c|}{a} & b \\ \hline
            \textbf{Classified as not a keyword by the automatic extraction} & c & d \\
    \hline
\end{tabular}
  \caption{Contingency table on results of detection and extraction.}
  \label{prerec}
\end{table}

答案1

tabular除非使用,否则您无法在环境中随意转到换行符tabularx。不过,幸运的是,有一个包可以填补这个空白,那就是makecell。您还可以更改字体样式(粗体、斜体),因此非常方便。

关于单元格的居中,您可以创建新的列类型,但需要加载包array

我也对您的表格进行了一些编辑:我删除了所有垂直线,因为没有它们内容仍然可读,它们变得多余,并添加了booktabs提供添加间距规则的命令。

表格图

\documentclass{article}
\usepackage{geometry}
\usepackage{booktabs}
\usepackage{makecell}

\renewcommand\theadalign{cb}
\renewcommand\theadfont{\bfseries}

\newcolumntype{C}[1]{>{\centering\arraybackslash}m{#1}}

\begin{document}

\begin{table}[h!]
 \centering
    \scriptsize
\begin{tabular}{C{4.5cm} C{4.5cm} C{4.5cm}}
\toprule
 & \thead{Classified as a keyword\\by the human} & \thead{Classified as not a\\keyword by the human} \\ \midrule
  \thead{Classified as a keyword by\\the automatic extraction} & a & b \\
  \thead{Classified as not a keyword\\by the automatic extraction} & c & d \\
\bottomrule
\end{tabular}
  \caption{Contingency table on results of detection and extraction.}
  \label{prerec}
\end{table}
\end{document}

相关内容