如何一起使用 \multirow 和 \multicolumn?

如何一起使用 \multirow 和 \multicolumn?

我在使用 \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-type 列有足夠的寬度,以便它們共同跨越 的寬度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} 

相關內容