1

Following is the code for this table:

\documentclass{article}
\usepackage{array, multirow}

\begin{document}
\begin{table}
    \centering
    \begin{tabular}{|c|*{20}{w{c}{0.5cm}|}}
        \hline
        \multirow{2}*{A} & \multicolumn{2}{c|}{1} & \multicolumn{2}{c|}{2} & \multicolumn{2}{c|}{3} & \multicolumn{2}{c|}{4} & \multicolumn{2}{c|}{5} & \multicolumn{2}{c|}{6} & \multicolumn{2}{c|}{7} & \multicolumn{2}{c|}{8} & \multicolumn{2}{c|}{9} & \multicolumn{2}{c|}{10} \\
        \cline{2-21}
        ~ & \multicolumn{2}{c|}{0} & \multicolumn{2}{c|}{0.1} & \multicolumn{2}{c|}{0.2} & \multicolumn{2}{c|}{0.3} & \multicolumn{2}{c|}{0.4} & \multicolumn{2}{c|}{0.5} & \multicolumn{2}{c|}{0.6} & \multicolumn{2}{c|}{0.7} & \multicolumn{2}{c|}{0.8} & \multicolumn{2}{c|}{0.9} \\
        \hline
        \multirow{2}*{B} & \multicolumn{5}{c|}{1} & \multicolumn{5}{c|}{2} & \multicolumn{5}{c|}{3} & \multicolumn{5}{c|}{4} \\
        \cline{2-21}
        ~ & \multicolumn{5}{c|}{1} & \multicolumn{5}{c|}{2} & \multicolumn{5}{c|}{3} & \multicolumn{5}{c|}{4} \\
        \hline
        \multirow{2}*{C} & \multicolumn{5}{c|}{1} & \multicolumn{5}{c|}{2} & \multicolumn{5}{c|}{3} & \multicolumn{5}{c|}{4} \\
        \cline{2-21}
        ~ & \multicolumn{5}{c|}{1} & \multicolumn{5}{c|}{2} & \multicolumn{5}{c|}{3} & \multicolumn{5}{c|}{4} \\        
        \hline
    \end{tabular}
    \caption{Caption}
    \label{tab:my_label}
\end{table}
\end{document}

I want for A row, the columns from 1 to 10 are equal; For B and C rows, the columns from 1 to 4 are equal.

enter image description here

Thanks!

--------------------------------Update---------------------------------------

The pic showed below is the table that I want.

enter image description here

Thanks.

0

1 Answer 1

2

Welcome to TeX.SE! Please, always provide MWE (Minimal Working Example), a small complete document, which reproduce your problem.

Your table has many errors:

  • the most of \multicolumn ar superfluous, consequently all this overwrite column settings

  • your table has only 11 columns, why you define 21?

  • correct code for your table is:

\documentclass{article}
\usepackage{array, multirow}

\begin{document}
\begin{table}
    \centering
    \begin{tabular}{|c|*{10}{w{c}{0.5cm}|}}
        \hline
\multirow{2}*{A} 
    & 1 & 2   & 3   & 4   & 5   & 6   & 7   & 8   & 9   & 10 \\
        \cline{2-11}
    & 0 & 0.1 & 0.2 & 0.3 & 0.4 & 0.5 & 0.6 & 0.7 & 0.8 & 0.9 \\
        \hline
\multirow{2}*{B} 
    & 1 & \multicolumn{4}{c|}{2} 
                & 3 & \multicolumn{4}{c|}{4}        \\
    \cline{2-11}
    & 1 & \multicolumn{4}{c|}{2}
                & 3 & \multicolumn{4}{c|}{4}        \\
    \hline
\multirow{2}*{C} 
    & 1 & \multicolumn{4}{c|}{2}
                & 3 & \multicolumn{4}{c|}{4}        \\
    \cline{2-11}
    & 1 & \multicolumn{4}{c|}{2}
                & 3 & \multicolumn{4}{c|}{4}        \\
    \hline
    \end{tabular}
    \caption{Caption}
    \label{tab:my_label}
\end{table}
\end{document}

enter image description here

Addendum:

According to your comment and showed new desired result in edited question:

  • it seems that this table formatting is not possible to get correctly with tabular, if \multicolumn cells merged more than four columns.
  • as solution, I found that this can be done by use of the tabularray package:
\documentclass{article}
\usepackage{geometry}
\usepackage{tabularray}
\NewTableCommand\mcc[1]{\SetCell[c=#1]{c} }
%---------------- Show page layout. Don't use in a real document!
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%---------------------------------------------------------------%

\begin{document}
    \begin{table}[ht]
    \centering
\begin{tblr}{hlines, vlines,
             colsep=4pt,
             colspec = {*{21}{Q[c, wd=1em]} }
                 }
\SetCell[r=2]{c}    A
    & \mcc{2} 0     &   & \mcc{2} 0.1   &   & \mcc{2} 0.2   &   & \mcc{2} 0.3   &   & \mcc{2} 0.4
                    &   & \mcc{2} 0.5   &   & \mcc{2} 0.6   &   & \mcc{2} 0.7   &   & \mcc{2} 0.8 
                    &   & \mcc{2} 0.9   \\
    & \mcc{2} 1     &   & \mcc{2}   2   &   & \mcc{2}   3   &   & \mcc{2}   4   &   & \mcc{2}   5
                    &   & \mcc{2}   6   &   & \mcc{2}   7   &   & \mcc{2}   8   &   & \mcc{2}   9
                    &   & \mcc{2}   10  \\
\SetCell[r=2]{c}    B
   & \SetCell[c=5]{c} 1 &   &   &   &   
                    & \mcc{5}{2}    &   &   &   &   
                            & \mcc{5}{3}    &   &   &   &  
                                    & \mcc{5}{4}    &   &   &   &       \\
   & \SetCell[c=5]{c} 1 &   &   &   &
                    & \mcc{5}{2}    &   &   &   &
                            & \mcc{5}{3}    &   &   &   &
                                    & \mcc{5}{4}    &   &   &   &       \\
\SetCell[r=2]{c}    C
   & \SetCell[c=5]{c} 1 &   &   &   &
                    & \mcc{5}{2}    &   &   &   &
                            & \mcc{5}{3}    &   &   &   &
                                    & \mcc{5}{4}    &   &   &   &       \\
   & \SetCell[c=5]{c} 1 &   &   &   &
                    & \mcc{5}{2}    &   &   &   &
                            & \mcc{5}{3}    &   &   &   &
                                    & \mcc{5}{4}    &   &   &   &       \\
\end{tblr}
\caption{Caption}
\label{tab:my_label}
    \end{table}
\end{document}

enter image description here

(red lines indicate page layout)

3
  • Thanks a lot for your answer. I defined 21 columns because I wanna the widths from second to fourth columns in B row and C row are equal too. Could you please see my updated question again, I add a new pic, that was what I want.
    – Sunandyou
    Commented May 2, 2022 at 13:14
  • @Sunandyou, from your question this is not evident. Answer only replicate first showed image. The new table seems that simple tabular table can't be designed. See addendum in my answer for possible solution.
    – Zarko
    Commented May 2, 2022 at 17:49
  • thanks for your help and solution, it runs in my document perfectly!
    – Sunandyou
    Commented May 2, 2022 at 20:51

You must log in to answer this question.

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