我无法使用 \multirow \multicolumn 创建表格
两个内容似乎重叠在一起,看起来不太好看。
我的完整 MWE:
\documentclass[12pt,oneside]{book}
\usepackage[showframe]{geometry}
\usepackage{amsmath}
\usepackage{ragged2e}
\usepackage{makecell, multirow, tabularx}
\renewcommand\theadfont{\small\bfseries} % for bold in table using \small
\renewcommand\theadgape{}
\usepackage[svgnames, table]{xcolor}
\usepackage{hhline, boldline}
\usepackage{seqsplit, caption} %for table spacing to second row
\usepackage{booktabs, ragged2e} % Use booktabs rules and get rid of vertical rules, ragged2e to ragged text
\usepackage{siunitx} %for table spacing to second row
\usepackage{threeparttable} %to add footnote below table
\usepackage{tabulary}
\usepackage{graphicx}
\usepackage[font=small,labelfont={bf,sf}, textfont={sf}, justification=centering]{caption}
\begin{document}
\begin{table}[h!]
\centering
\sisetup{table-format=3.0, table-number-alignment=center, table-column-width=2.0cm}
\begin{tabular}{lSS}
\toprule
\multirow{2}{*}{\textbf{Test Cases (Class A \& Class B)}} & \multicolumn{2}{c}{\thead{\makebox[0pt]{Arrangement Accuracy (\%)}}}\\
\cmidrule{2-3}
&{\textbf{AM}}
& {\textbf{FM}} \\
\midrule
Pairs of Samples 1 (A5 \& B42) & 333.33 & 1300.00 \\
Pairs of Samples 2 (A20 \& B44) & 47.44 & 77.35 \\
\bottomrule
\end{tabular}
\end{table}
\end{document}
答案1
标题元素几乎发生碰撞的表面原因是指令
\multicolumn{2}{c}{\thead{\makebox[0pt]{Arrangement Accuracy (\%)}}}
然而,不是\multicolumn
导致问题的原因是指令(从您帖子的标题中可以推测)。相反,是使用,\makebox[0pt]{...}
这导致 LaTeX 不考虑实际可用的宽度(即 2*2cm+2\tabcolsep)而沿线向下移动。请注意,标题行在两侧都突出,而不仅仅是左侧。
无论如何,我认为你应该简化标题设置,以允许每个S
类型列有足够的宽度,以便它们共同跨越宽度Arrangement Accuracy (\%)
。哦,我看不出使用粗体在标题行中——除非你考虑对你的读者大喊大叫是一个正当的理由。(我不……)
\documentclass[12pt,oneside]{book}
%% Condensed preamble to the bare minimum:
\usepackage{geometry,{booktabs, ragged2e,siunitx}
\begin{document}
\begin{table}[h!]
\centering
\sisetup{table-format=6.4}
\begin{tabular}{@{} lSS @{}}
\toprule
Test Cases (Class A \& Class B) & \multicolumn{2}{c@{}}{Arrangement Accuracy (\%)}\\
\cmidrule(l){2-3}
& AM & FM \\
\midrule
Pairs of Samples 1 (A5 \& B42) & 333.33 & 1300.00 \\
Pairs of Samples 2 (A20 \& B44) & 47.44 & 77.35 \\
\bottomrule
\end{tabular}
\end{table}
\end{document}