1

I am having trouble to create a table using both \multirow \multicolumn

Both contents seemed to overlap together and look not nice.

enter image description here

My Full 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
  • The arguments of the \sisetup instructions are in conflict with each other and the actual contents of the S-type columns. What are you trying to achieve?
    – Mico
    Nov 28, 2019 at 11:57

1 Answer 1

2

The superficial reason for the near-collision of the header elements is the instruction

\multicolumn{2}{c}{\thead{\makebox[0pt]{Arrangement Accuracy (\%)}}}

However, it is not the \multicolumn instruction (as one might surmise from the title of your posting) that's the cause of the problem. Instead, it's the use of \makebox[0pt]{...}, which makes LaTeX plunk down the line without regard for the actually available width (which is 2*2cm+2\tabcolsep). Observe that the header line protrudes on both sides, not just the left-hand side.

Anyway, I think you should simplify the header setup to allow each S-type column enough width so that they jointly span the width of Arrangement Accuracy (\%). Oh, and I can see no (valid) reason for using boldface in the header row -- unless you consider shouting at your readers to be a valid reason. (I don't...)

enter image description here

\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} 
6
  • thanks. Is there any way to make Test Cases (Class A & Class B) in the middle of the box?
    – aan
    Nov 28, 2019 at 13:12
  • @aan - Just encase the string in a \multicolumn{1}{@{}c}{...} directive. You won't see much of a difference, though, as the string Test Cases (Class A & Class B) is almost as long as the string Pairs of Samples 2 (A20 \& B44).
    – Mico
    Nov 28, 2019 at 13:28
  • thanks. Do you mean \multicolumn{1}{@{}c}{Test Cases (Class A \& Class B)} No different. Any way to make the content in the middle?
    – aan
    Nov 28, 2019 at 13:36
  • @aan - The reason it's "no different" is already given in my earlier comment. Maybe "not much of a difference" was too subtle a caution.
    – Mico
    Nov 28, 2019 at 13:42
  • 1
    @aan: Please clarify: do you wan the text to be a) vertically centered or b) horizontally centered?
    – leandriis
    Nov 29, 2019 at 19:28

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .