下面是我为想要创建的数据表编写的代码:
\begin{tabular}{|l|l|l|l|l|l|}
\hline
\multirow{2}{*}{Time (t)} & \multicolumn{4}{|c|}{Position (cm)} & \multirow{2}{*}{SDOM}\\
& Trial 1 & Trial 2 & Trial 3 & Average & \\ \hline
0.00 & 0.00 & 0.00 & 0.00 & 0.00 & 0.00\\ \hline
%more data here
\end{tabular}
目前它生产
我当然想在试验/平均值上方画一条线。有人知道怎么做吗?
谢谢您的帮助!
答案1
正如@frabjous 在评论中指出的那样,您可以通过\cline{2-5}
在之后立即插入指令来实现格式化目标\multirow{2}{*}{SDOM}\\
。
也就是说,也请考虑通过以下方法让您的表格看起来更加开放和吸引人:(a)删除所有垂直规则 - 相信我,它们不会被忽略 - 以及(b)用一些用户宏替换基本的 LaTeX 指令\hline
和\cline
booktabs 包: \toprule
,,,和。与监狱牢房窗户一样吸引人的物体(带有许多垂直和水平的栅栏)相比\midrule
,您的读者更有可能花时间欣赏造型优美的桌子……\bottomrule
\cmidrule
\documentclass{article}
\usepackage{multirow, % for \multirow macro
booktabs, % \toprule, \midrule, \bottomrule, \cmidrule macros
amsmath, % \smash[b] macro
array, % 'w' column type
calc} % \widthof macro
\newcommand{\mytab}[1]{%
\smash[b]{\begin{tabular}[t]{@{}c@{}} #1 \end{tabular}}}
\begin{document}
\centering
\begin{tabular}{| *{6}{c|} }
\hline
\multirow{2}{*}{Time (t)} & \multicolumn{4}{c|}{Position (cm)} & \multirow{2}{*}{SDOM}\\
\cline{2-5}
& Trial 1 & Trial 2 & Trial 3 & Average & \\
\hline
0.00 & 0.00 & 0.00 & 0.00 & 0.00 & 0.00\\
\hline
\end{tabular}
\bigskip
\begin{tabular}{@{} c *{4}{wc{\widthof{Trial 1}}} c @{}}
%% (the 'w' column type takes a width argument)
\toprule
\mytab{Time\\(s)} & \multicolumn{4}{c}{Position (cm)} & SDOM \\
\cmidrule(lr){2-5}
& Trial 1 & Trial 2 & Trial 3 & Avg. \\
\midrule
0.00 & 0.00 & 0.00 & 0.00 & 0.00 & 0.00\\
0.10 & 0.00 & 0.00 & 0.00 & 0.00 & 0.00\\
0.22 & 0.00 & 0.00 & 0.00 & 0.00 & 0.00\\
\bottomrule
\end{tabular}
\end{document}
答案2
您可能喜欢使用该tabularray
包的解决方案。与 @Mico 答案 (+1) 类似,提出了两个示例:
- 水平线与垂直线
booktabs
仅使用包中定义的真正需要的水平规则和包S
中定义的列siunitx
:
\documentclass{article}
\usepackage{tabularray}
\UseTblrLibrary{booktabs, siunitx}
\begin{document}
\centering
\begin{tblr}{hlines, vlines,
colspec = {l *{5}{c}}
}
\SetCell[r=2]{c} Time (t)
& \SetCell[c=4]{c} Position (cm)
& & & & \SetCell[r=2]{c} SDOM \\
& Trial 1 & Trial 2 & Trial 3 & Average & \\
0.00 & 0.00 & 0.00 & 0.00 & 0.00 & 0.00 \\
\end{tblr}
\bigskip
\begin{tblr}{colspec = {*{6}{Q[c, si={table-format=1.2}]}},
row{1,2}= {guard}
}
\toprule
\SetCell[r=2]{c} Time (t)
& \SetCell[c=4]{c} Position (cm)
& & & & \SetCell[r=2]{c} SDOM \\
\hline
& Trial 1 & Trial 2 & Trial 3 & Average & \\
\midrule
0.00 & 0.00 & 0.00 & 0.00 & 0.00 & 0.00 \\
\bottomrule
\end{tblr}
\end{document}
答案3
\documentclass{article}
\usepackage{tabularray}
\begin{document}
\begin{tblr}
{
colspec={llllll},
cell{1}{1}={r=2}{c},
cell{1}{Z}={r=2}{c},
cell{1}{2}={c=4}{c},
cell{2}{2-5}={}{c},
hline{1-Z}={.03em},
vline{1-Z}={.03em}
}
Time (t) & Position (cm) & & & & SDOM \\
& Trial 1 & Trial 2 & Trial 3 & Average & \\
0.00 & 0.00 & 0.00 & 0.00 & 0.00 & 0.00 \\
0.00 & 0.000000000 & 0.00 & 0.00 & 0.00 & 0.00 \\
\end{tblr}
\end{document}
\documentclass{article}
\usepackage{tabularray}
\begin{document}
\begin{tblr}
{
colspec={llllll},
cell{1}{1}={r=2}{c},
cell{1}{Z}={r=2}{c},
cell{1}{2}={c=4}{c},
cell{2}{2-5}={}{c},
hline{1,Z}={.08em},
hline{2}={.05em},
hline{3-Y}={.03em}
}
Time (t) & Position (cm) & & & & SDOM \\
& Trial 1 & Trial 2 & Trial 3 & Average & \\
0.00 & 0.00 & 0.00 & 0.00 & 0.00 & 0.00 \\
0.00 & 0.000000000 & 0.00 & 0.00 & 0.00 & 0.00 \\
\end{tblr}
\end{document}