Search code examples
latexmultirow

Latex multirow and multicolumn table


I struggle with a multirow, multicolumn table in latex. So far I have this (messy) code:

\begin{tabular}{cccccccccc}
    \toprule
    \multirow{2}{*}{\textbf {A}} &
    \multirow{2}{*}{\textbf {B}} &
    \multirow{2}{*}{\textbf {C}} &
    \multicolumn{3}{c}{\textbf {D}} && D1 & D2 & D3 &
    \multicolumn{3}{c}{\textbf {E}}   && E1 & E2 & E3 &
    \multirow{2}{*}{\textbf {F}}\\
    \cmidrule(lr){1-10}
    a & b & c & d1 & d2 & d3 & e1 & e3 & e3 & f\\
    aa & bb & cc & dd1 & dd2 & dd3 & ee1 & ee3 & ee3 & ff
    \bottomrule
\end{tabular}

Ideally the table would look like this:

multicolumn, multirow table

Subheader D1-E3 should not be bold....

Any help is appreciated.


Solution

  • You need to input D1, .... , E3 as a separate row:

    \documentclass{article}
    
    \usepackage{booktabs}
    \usepackage{multirow}
    \usepackage{makecell}
    \renewcommand\theadfont{\normalsize\bfseries}
    
    \begin{document}
    
    \begin{tabular}{cccccccccc}
        \toprule
        \multirow{2}{*}[-4pt]{\thead{A}} &
        \multirow{2}{*}[-4pt]{\thead{B}} &
        \multirow{2}{*}[-4pt]{\thead{C}} &
        \multicolumn{3}{c}{\thead{D}} &
        \multicolumn{3}{c}{\thead{E}} & 
        \multirow{2}{*}[-4pt]{\thead{F}}\\
        \cmidrule(lr){4-6}
        \cmidrule(lr){7-9}
        &&& D1 & D2 & D3 & E1 & E2 & E3 &\\
        \midrule
        a & b & c & d1 & d2 & d3 & e1 & e3 & e3 & f\\
        aa & bb & cc & dd1 & dd2 & dd3 & ee1 & ee3 & ee3 & ff\\
        \bottomrule
    \end{tabular}
    
    
    \end{document}
    

    (I would not use vertical lines together with the booktabs package, so I replaced it with a split horizontal line)

    enter image description here