![如何绘制具有多个字段的多行多列表格](https://linux22.com/image/302012/%E5%A6%82%E4%BD%95%E7%BB%98%E5%88%B6%E5%85%B7%E6%9C%89%E5%A4%9A%E4%B8%AA%E5%AD%97%E6%AE%B5%E7%9A%84%E5%A4%9A%E8%A1%8C%E5%A4%9A%E5%88%97%E8%A1%A8%E6%A0%BC.png)
我需要创建下面给出类型的表格。但我没有得到这个。这里有人能帮我吗?谢谢
答案1
使用该包,您可以获得比图像更整洁的东西makecell
(允许在单元格内换行,以及列标题的常见格式),booktabs
以及siunitx
使用数值格式化列
\documentclass[a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage{multirow}
\usepackage[showframe, nomarginpar]{geometry}
\usepackage{array, booktabs, makecell}
\renewcommand\theadfont{\bfseries}
\usepackage{siunitx}
\sisetup{table-format=-3.2, table-number-alignment=center}
\newcolumntype{T}{S[table-format=2.2]}
\newcolumntype{U}{S[table-format=1.2]}
\begin{document}
{\centering\small\setlength\tabcolsep{5pt}
\begin{tabular}{@{\,}lc STTSSTU@{\,}}
\multicolumn{9}{c}{\thead{Paired Samples Test}} \\
\toprule
& & \multicolumn{5}{c}{\thead{Paired Differences}} & & \\
\cmidrule(lr){3-7}
\multirowthead{4}{Type\\of test} & \multirowthead{4}{Comparison} & {\multirowthead{4}{Mean}} & {\multirowthead{4}{Std.\\Deviation}} & {\multirowthead{4}{Std.\\Error Mean}} & \multicolumn{2}{c}{\thead{95\% Confidence\\Interval of the\\ Difference}}
& {\multirowthead{4}{\boldmath$t$ value}} & {\multirowthead{4}{d.f.}}\\%
\cmidrule(lr){6-7}
& & & & & {\thead{Lower}} & {\thead{Upper}} & & \\
\midrule
Pair 1 & \makecell{Hybrid GA\\Path Cost} & -507.00 & 54.01 & 31.18 & -641.17 & -372.83 & -16.26 &2.00 \\
\bottomrule
\end{tabular}}
\end{document}
答案2
您可以使用multirow
包。请注意,\multirow
表示生成单元格中显示的行数 - 它不必对应于逻辑\\
行(源代码中以该行结尾的行)。
第二个参数是生成的列的宽度或*
自动计算。
\documentclass{article}
\usepackage{multirow}
\begin{document}
\begin{tabular}{|l|p{5em}|c|c|c|c|c|c|c|}
\hline
\multicolumn{9}{|c|}{Paired Samples Test} \\
\hline
\multirow{5}{3em}{Type of test} &
\multirow{5}{*}{Comparison} &
\multicolumn{5}{|c|}{Paired Differences} &
\multirow{5}{*}{$t$ value} &
\multirow{5}{*}{d.f.} \\
\cline{3-7}
& & \multirow{4}{*}{Mean} &
\multirow{4}{4em}{Std.\ Deviation} &
\multirow{4}{3em}{Std.\ Error Mean} &
\multicolumn{2}{|p{7em}|}{\centering 95\% Confidence Interval of the Difference} &
& \\
\cline{6-7}
& & & & & Lower & Upper & & \\
\hline
Pair 1 & Hybrid GA Path Cost & -507.00 & 1 & 2 & 3 & 7 & 8 & 9 \\
\hline
\end{tabular}
\end{document}