HumanTorch
HumanTorch

Reputation: 359

How to create a multirow multicolumn table with subheadings below the first row

I am attempting to create a table in latex as below, although I am a bit confused about where and when the \multirow and \multicolumn commands are to be used inside a tabular environment. Col_1, Col_2, and Col_3 are supposed to be subheadings but they need to appear in the second row.

What I started off with is, (the columns are duplicated, so I wanted to split it into multiple rows as shown in the image) :

\begin{table}[H]
  \begin{tabular}{lSSSSSSSS}
    \toprule
    \multirow{2}{*}{\textbf{A}} &
      \multicolumn{3}{c}{\textbf{Model_1}} &
      \multicolumn{5}{c}{\textbf{Model_2}}  \\
      & {Col_1} & {Col_2} & {Col_3} & {Col_1} & {Col_2} & {Col_3} & {Col_4} & {Col_5} \\
      \midrule
    x\% & a\% b\% & c\% & x\% & y\% & z\% & 0. & 0.  \\
    \bottomrule
  \end{tabular}
  \caption{results}
\end{table}

table

Upvotes: 0

Views: 2353

Answers (1)

You can place your subheaders in a row of their own, no need to worry about mutirows and such

\documentclass{article}

\usepackage{siunitx}
%\usepackage{booktabs}
\usepackage{float}

\begin{document}

\begin{table}[H]
  \begin{tabular}{l|S|S|S}
    \textbf{A} & \multicolumn{3}{c}{x\%} \\
    \hline
    & {Col\_1} & {Col\_2} & {Col\_3} \\
    Model\_1 & a\% & b\% & c\% \\
    \hline
    Model\_2 & x\% & y\% & z\% \\
  \end{tabular}
  \caption{results}
\end{table}


\end{document}

Instead of the layout you show in your image, I rather suggest to avoid vertical lines for a more professional looking result:

\documentclass{article}

\usepackage{siunitx}
\usepackage{booktabs}

\begin{document}

\begin{table}[htbp]
\centering
\begin{tabular}{@{}lSSSSSSSS@{}}
    \toprule
    \textbf{A} &
      \multicolumn{3}{c}{\textbf{Model\_1}} &
      \multicolumn{5}{c}{\textbf{Model\_2}}  \\
      & {Col\_1} & {Col\_2} & {Col\_3} & {Col\_1} & {Col\_2} & {Col\_3} & {Col\_4} & {Col\_5} \\
      \cmidrule(r){2-4}\cmidrule(l){5-9}
    x\% & a\% &  b\% & c\% & x\% & y\% & z\% & 0. & 0.  \\
    \bottomrule
  \end{tabular}
  \caption{results}
\end{table}

\end{document}

enter image description here

Upvotes: 1

Related Questions