0

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.

  • 1
    welcome to TEXSE, could you make your script compilable? – Raaja Sep 26 at 11:08
0

I tried to clean your code a little bit.

Here is the result:

\documentclass{article}

\usepackage{booktabs}
\usepackage{multirow}


\begin{document}

    \begin{tabular}{*{10}{c}}
        \toprule
        \multirow{2}{*}{\textbf{A}} & \multirow{2}{*}{\textbf{B}} & \multirow{2}{*}{\textbf{C}} &
        \multicolumn{3}{c}{\textbf{D}} & \multicolumn{3}{c}{\textbf{E}} & \multirow{2}{*}{\textbf{F}}\\
        \cmidrule{4-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}

It renders like this:

enter image description here

However, if you absolutely need the vertical line, I have no idea how to do it on two rows only...

Enjoy!

  • No, the vertical line isn't a must. Thank your for your code. I got another solution here: stackoverflow.com/questions/58115402/… which introduces a small gap instead of the vertical line, also very nice layout. Anyway, thanks a lot for your prompt answer. – mati Sep 26 at 11:56
1

I more like the following table design:

enter image description here

\documentclass{article}

\usepackage{booktabs, makecell, multirow}
\renewcommand\theadfont{\bfseries\normalsize}
\renewcommand\theadgape{}


\begin{document}
    \begin{tabular}{*{10}{c}}
    \toprule
\multirow{2.5}{*}{\thead{A}} 
    & \multirow{2.5}{*}{\thead{B}} 
        & \multirow{2.5}{*}{\thead{C}} 
            &   \multicolumn{3}{c}{\thead{D}} 
                & \multicolumn{3}{c}{\thead{E}} 
                    & \multirow{2.5}{*}{\thead{F}}    \\
    \cmidrule(l){4-6}   \cmidrule(l){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}
  • is the '2.5' first argument of \multirow the reason for which the A, B, C and F are centered regarding the \cmidrule commands, compared to my solution? I used '2' instead and I got a small shift. – Alexandre Quenon Oct 4 at 14:54
  • 1
    @AlexandreQuenon, yes. With this is considered spaces around rules (below of \toprule, around \cmisrule` and above of the \midrule) which sum is about 0.5\baselineskip. This is nice new features of recent ˙multirow` package. – Zarko Oct 4 at 15:47
-1

Added the vertical lines to @Alexandre Quenon (EDIT:Sorry got confused) solution

\documentclass{article}

\usepackage{booktabs}
\usepackage{multirow}


\begin{document}

    \begin{tabular}{cccccccccc}
        \toprule
        \multirow{2}{*}{\textbf{A}} & \multirow{2}{*}{\textbf{B}} & \multirow{2}{*}{\textbf{C}} &
        \multicolumn{3}{c|}{\textbf{D}} & \multicolumn{3}{|c}{\textbf{E}} & \multirow{2}{*}{\textbf{F}}\\
        \cmidrule{4-9}
        &&&  D1 & D2 & \multicolumn{1}{c|}{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}

Result

  • it works but the problem is that you don't have a continuous vertical line, which is quite the opposite of what you usually want. – Alexandre Quenon Sep 26 at 12:04
  • Yeah, it gets closer when you use \hline but then the head looks not so nice. – Sango Sep 26 at 12:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.