![如何使用嵌套多列和多行](https://linux22.com/image/318897/%E5%A6%82%E4%BD%95%E4%BD%BF%E7%94%A8%E5%B5%8C%E5%A5%97%E5%A4%9A%E5%88%97%E5%92%8C%E5%A4%9A%E8%A1%8C.png)
我想制作一个好的 table on table,但我不是专家。下面是我的标签代码
\documentclass{article}
\usepackage{times}
\usepackage{multirow}
\begin{document}
% Article top matter
\begin{table*}[!t]
\centering
\caption{Vehicle Info}
\begin{tabular}{|c|c|c|c|c|c|c|c|c|}
\hline
% \multirow{2}{*}{Object} & \multicolumn{1}{c|}{\multirow{2}{*}{\textbf{Action}}} & \multicolumn{6}{c|}{\textbf{RMS Errors}} & \textbf{Leave/Off} & \multirow{2}{*}{\textbf{Total}} \\
\multirow{2}{*}{Object} & \multirow{2}{*}{Action} & \multirow{2}{*}{Part} & \multicolumn{6}{c|}{\textbf{Values}} \\
\cline{4-9}
& \multicolumn{1}{c|}{} & & \textbf{X}(mm) & \textbf{Y}(mm) & \textbf{Z}(mm) & \textbf{Roll}(deg) & \textbf{Pitch}(deg) & \textbf{Yaw}(deg) \\
\hline
car & Drive & Wheel & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 \\
car & Drive & Gear & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 \\
\hline
car & Park & Wheel & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 \\
car & Park & Gear & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 \\
\hline
car & Uphill & Wheel & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 \\
car & Uphill & Gear & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 \\
\hline
truck & Drive & Wheel & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 \\
truck & Drive & Gear & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 \\
\hline
truck & Park & Wheel & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 \\
truck & Park & Gear & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 \\
\hline
truck & Uphill & Wheel & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 \\
truck & Uphill & Gear & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 \\
\hline
\hline
\end{tabular}
\label{tab:pro_pro}
\end{table*}
我的表格图片附在下面。但是我想制作表格,这样我就不必在列中写 6 次汽车、卡车,而是只写一次。对于 Action 列,我也必须写 2 次。我可以在下面获得一些帮助或修改我的代码吗?谢谢
答案1
不需要\multirow
;当正文中的某个表格单元格为空白时,就理解为其上方的值是重复的。
删除垂直规则和不必要的水平规则将有助于更好地阅读表格。
\documentclass{article}
\usepackage{newtxtext,newtxmath}
\usepackage{booktabs}
\usepackage{geometry} % just not to bother with the table width
\begin{document}
% Article top matter
\begin{table}
\centering
\caption{Vehicle Info}\label{tab:pro_pro}
\begin{tabular}{lllcccccc}
\toprule
\textbf{Object} & \textbf{Action} & \textbf{Part} & \multicolumn{6}{c}{\textbf{Values}} \\
\cmidrule{4-9}
& & & $X$ (mm) & $Y$ (mm) & $Z$ (mm) & Roll (deg) & Pitch (deg) & Yaw (deg) \\
\midrule
car & Drive & Wheel & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 \\
& & Gear & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 \\
\addlinespace
& Park & Wheel & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 \\
& & Gear & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 \\
\addlinespace
& Uphill & Wheel & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 \\
& & Gear & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 \\
\midrule
truck & Drive & Wheel & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 \\
& & Gear & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 \\
\addlinespace
& Park & Wheel & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 \\
& & Gear & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 \\
\addlinespace
& Uphill & Wheel & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 \\
& & Gear & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 \\
\bottomrule
\end{tabular}
\end{table}
\end{document}
答案2
该表的一个漂亮版本:
\documentclass{article}
\usepackage{newtxtext,newtxmath}
\usepackage{booktabs}
\usepackage{multirow}
\usepackage{geometry} % just not to bother with the table width
\begin{document}
% Article top matter
\begin{table}
\centering
\caption{Vehicle Info}
\label{tab:pro_pro}
\begin{tabular}{@{\hspace{1cm}}ll ccc ccc}
\toprule
\multirow{2}{*}{\textbf{Action}} &
\multirow{2}{*}{\textbf{Part}} &
\multicolumn{5}{c}{\textbf{Values}} \\
\cmidrule{3-8}
& & $X$ (mm) & $Y$ (mm) & $Z$ (mm) & Roll (deg) & Pitch (deg) & Yaw (deg) \\
\midrule
\multicolumn{8}{l}{\textbf{Car}}\\\cmidrule{1-1}
\multirow{2}{*}{Drive} & Wheel & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 \\
& Gear & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 \\
\addlinespace
\multirow{2}{*}{Park} & Wheel & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 \\
& Gear & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 \\
\addlinespace
\multirow{2}{*}{Uphill} & Wheel & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 \\
& Gear & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 \\
\multicolumn{8}{l}{\textbf{Truck}}\\\cmidrule{1-1}
\multirow{2}{*}{Drive} & Wheel & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 \\
& Gear & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 \\
\addlinespace
\multirow{2}{*}{Park} & Wheel & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 \\
& Gear & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 \\
\addlinespace
\multirow{2}{*}{Uphill} & Wheel & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 \\
& Gear & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 \\
\bottomrule
\end{tabular}
\end{table}
\end{document}