表格展开单元格

表格展开单元格

我有下表。我正在寻找一种方法,以便第一行中的文本(“类别”、“关键字计数”)显示在列的中间。到目前为止,我手动将它们放在中间列,但它会扩展整个列,而不仅仅是单个文本单元格。我该如何改变这种情况?我不确定我是否被允许在此项目中使用 tabularx,所以我欢迎没有它的解决方案。谢谢

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{booktabs}
\usepackage{graphicx}

\newcommand*\rot{\rotatebox{90}}

\begin{document}


\begin{table}
\begin{tabular}{l|cccccccccc}
    \toprule
    \textbf{Categories} & & & & & \textbf{Keywords count}\\
    \midrule
     & \rot{key1} & \rot{key2} & \rot{key3} & \rot{key4} & \rot{key5} & \rot{key6}  & \rot{key7}    & \rot{key8} & \rot{key9}\\
    \midrule
     \textbf{C1} (S1, S2) & & 14* & & & & & 9 & 5 & 7 \\
     \midrule
     \textbf{C2} (S1, S11) & & & & & & & 4 & 3 & 5* \\
     \midrule
     \textbf{C3} (S3, S4) & & 5* & 3 & & & 4 & & \\
     \midrule
     \textbf{C4} (S4, S5, S6) & & 8* & & & 5 & 3 & & & \\
     \midrule
     \textbf{C5} (S7, S8, S9) & 31* & 12 & 24 & & 5 & & & & \\
     \midrule
     \textbf{C6} (S10, S11, S12) & & 5 & & 8* & & & & 7 & \\
     \midrule
     \textbf{C7} (S12, S13) & & & & 7* & & & 4 & 6 & \\
     \midrule
     \textbf{C8} (S11, S12, S13) & & & & & & 4 & 7* & 4 & 5 \\
     \midrule
     \textbf{C9} (S12, S16) & & 8 & & 11* & & & & 5 & \\
     \midrule
     \textbf{C10} (S15, S17) & & 4 & & 6* & & & & & \\
     \bottomrule\\
\end{tabular}
\label{tab:keywords}
\end{table}

\end{document}

答案1

查找\multicolumn命令(标准 LaTeX 表)。这里:

 \multicolumn{9}{c}{\textbf{Keywords count}}

在此处输入图片描述

\documentclass{article}
\usepackage{rotating,booktabs}
\newcommand*\rot{\rotatebox{90}}
\begin{document}
\begin{tabular}{l|ccccccccc}
    \toprule
    \textbf{Categories} & \multicolumn{9}{c}{\textbf{Keywords count}}\\
    \midrule
     & \rot{key1} & \rot{key2} & \rot{key3} & \rot{key4} & \rot{key5} & \rot{key6}  & \rot{key7}    & \rot{key8} & \rot{key9}\\
    \midrule
     \textbf{C1} (S1, S2) & & 14* & & & & & 9 & 5 & 7 \\
     \midrule
     \textbf{C2} (S1, S11) & & & & & & & 4 & 3 & 5* \\
     \midrule
     \textbf{C3} (S3, S4) & & 5* & 3 & & & 4 & & \\
     \midrule
     \textbf{C4} (S4, S5, S6) & & 8* & & & 5 & 3 & & & \\
     \midrule
     \textbf{C5} (S7, S8, S9) & 31* & 12 & 24 & & 5 & & & & \\
     \midrule
     \textbf{C6} (S10, S11, S12) & & 5 & & 8* & & & & 7 & \\
     \midrule
     \textbf{C7} (S12, S13) & & & & 7* & & & 4 & 6 & \\
     \midrule
     \textbf{C8} (S11, S12, S13) & & & & & & 4 & 7* & 4 & 5 \\
     \midrule
     \textbf{C9} (S12, S16) & & 8 & & 11* & & & & 5 & \\
     \midrule
     \textbf{C10} (S15, S17) & & 4 & & 6* & & & & & \\
     \bottomrule
\end{tabular}
\end{document}

相关内容