# Latex multicolumn, multirow 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:

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

Any help is appreciated.

• welcome to TEXSE, could you make your script compilable? Sep 26, 2019 at 11:08

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:

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, 2019 at 11:56

I more like the following table design:

\documentclass{article}

\usepackage{booktabs, makecell, multirow}

\begin{document}
\begin{tabular}{*{10}{c}}
\toprule
\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. Oct 4, 2019 at 14:54
• @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. Oct 4, 2019 at 15:47

If you really want to add vertical rules compatible with the horizontal rules of booktabs (which is not at all in the spirit of booktabs) you should try {NiceTabular} of nicematrix. That environment creates PGF/Tikz nodes under the cells, rows and columns of the tabular and it's possible to use these nodes to draw whatever rule you want with Tikz.

\documentclass{article}

\usepackage{booktabs}
\usepackage{nicematrix}
\usepackage{tikz}

\begin{document}
\begin{NiceTabular}{*{10}{c}}
\toprule
\RowStyle{\bfseries}
\Block{2-1}{A}
& \Block{2-1}{B}
& \Block{2-1}{C}
& \Block{1-3}{D}
&&& \Block{1-3}{E}
&&& \Block{2-1}{F}    \\
\cmidrule(l){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
\CodeAfter \tikz \draw (1-|7) -- (3-|7) ;
\end{NiceTabular}
\end{document}


You need several compilations because nicematrix uses PGF/Tikz nodes.

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}


• 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. Sep 26, 2019 at 12:04
• Yeah, it gets closer when you use \hline but then the head looks not so nice. Sep 26, 2019 at 12:07
• Instead of \cmidrule{4-9} you can consider using \cline{4-9} Jul 26, 2021 at 17:40