我怎样才能在乳胶中实现这个表格
目前的结果如下
通过使用此代码
\begin{table}[]
\centering
\caption{My caption}
\label{my-label}
\begin{tabular}{|l|l|l|l|l|l|l|l|}
\hline
\multirow{2}{*}{Criteria} & \multirow{2}{*}{Expected} & \multicolumn{3}
{l|}{Actual } & \multirow{2}{*}{Matching Rate} \\ \cline{3-7}
& & Trial 1 & Trial 2 & Trial 3 & Trial 4 & Trial 5 \\ \cline{3-7} \hline
\end{tabular}
\end{table}
答案1
像这样吗?
\documentclass[10pt,a4paper]{article}
\usepackage{multirow}
\begin{document}
\begin{table}[]
\begin{tabular}{|c|c|c|c|c|c|c|c|}
\hline
\multirow{2}{*}{\textbf{Criteria}} & \multirow{2}{*}{\textbf{Expected}} & \multicolumn{5}{c|}{\textbf{Actual}} & \multirow{2}{*}{\textbf{\begin{tabular}[c]{@{}c@{}}Matching\\ rate\end{tabular}}} \\ \cline{3-7}
& & \textbf{\begin{tabular}[c]{@{}c@{}}Trial\\ 1\end{tabular}} & \textbf{\begin{tabular}[c]{@{}c@{}}Trial\\ 2\end{tabular}} & \textbf{\begin{tabular}[c]{@{}c@{}}Trial\\ 3\end{tabular}} & \textbf{\begin{tabular}[c]{@{}c@{}}Trial\\ 4\end{tabular}} & \textbf{\begin{tabular}[c]{@{}c@{}}Trial\\ 5\end{tabular}} & \\ \hline
\multicolumn{1}{|l|}{\begin{tabular}[c]{@{}l@{}}The device can\\ detect drowsiness\end{tabular}} & \textbf{\begin{tabular}[c]{@{}c@{}}2 to 3 \\ seconds\end{tabular}} & 2 sec & 3 sec & 2 sec & 2 sec & 2 sec & 100\% \\ \hline
\multicolumn{7}{|r|}{\textbf{Functionality}} & \textbf{100\%} \\ \hline
\end{tabular}
\end{table}
\end{document}
要得到:
答案2
{NiceTabular}
供参考,这里有一种使用创建该表的方法nicematrix
。
\documentclass[10pt,a4paper]{article}
\usepackage{geometry}
\usepackage{nicematrix}
\begin{document}
\begin{table}
\centering
\begin{NiceTabular}{m[l]{2.7cm}cccccccccc}[hvlines,cell-space-limits=3pt]
\RowStyle[nb-rows=2]{\bfseries}
\Block[c]{2-1}{Criteria} & \Block{2-1}{Expected} & \Block{1-5}{Actual} &&&&& \Block{2-1}{Matching \\ rate} \\
& & \Block{}{Trial\\ 1} & \Block{}{Trial\\ 2} & \Block{}{Trial\\ 3} & \Block{}{Trial\\ 4} & \Block{}{Trial\\ 5} \\
The device can detect drowsiness & \bfseries \Block{}{2 to 3 \\ seconds}
& 2 sec & 3 sec & 2 sec & 2 sec & 2 sec & 100\% \\
\RowStyle{\bfseries}
\Block[r]{1-7}{Functionality} &&&&&&& 100\%
\end{NiceTabular}
\end{table}
\end{document}
您需要进行多次编译(因为nicematrix
在后台使用了 PGF/TikZ 节点)。
然而,我建议采用本着 精神的设计booktabs
。
答案3
和tabularray
:
\documentclass{article}
\usepackage{geometry}
\usepackage{caption}
\usepackage{tabularray}
\begin{document}
\begin{table}\centering
\caption{My table with \texttt{tabularray}}\label{my-label-t}
\begin{tblr}{
colspec={X[l]*{7}{c}},
hlines, vlines,
row{1,2,Z}={font=\bfseries},
column{2}={font=\bfseries}
}
\SetCell[r=2]{c}Criteria & \SetCell[r=2]{c}Expected & \SetCell[c=5]{c}Actual &&&&& \SetCell[r=2]{c}{Matching\\ Rate} \\
& & {Trial\\ 1} & {Trial\\ 2} & {Trial\\ 3} & {Trial\\ 4} & {Trial\\ 5} &\\
The device can detect drowsiness & 2 sec & 3 sec & 2 sec & 2 sec & 2 sec & 100\% \\
\SetCell[c=7]{r} Functionality &&&&&&& 100\%
\end{tblr}
\end{table}
\end{document}