4

I would like remove the two lines in yellow from my code

\begin{tabular}{|c|c|c|c||c|c|c|}
\hline
 \multirow{3}{*}{} & \multicolumn{6}{c|}{40 Mod}\\
\hline 
     &  \multicolumn{3}{c||}{method A}  &  \multicolumn{3}{c|}{method B} \\
\hline
     &  1 & 2 & 3 & 1 & 2 & 3 \\
\hline
0 & 0.68 & 0.81 & 0.73 & 0.67 & 0.86 & 0.74 \\
1 & 0.93 & 0.87 & 0.90 & 0.93 & 0.89 & 0.91 \\
2 & 0.98 & 0.92 & 0.94 & 0.98 & 0.91 & 0.94 \\
3 & 0.35 & 0.30 & 0.32 & 0.34 & 0.30 & 0.32 \\
\hline
\end{tabular}

enter image description here

3

4 Answers 4

6

This an alternative, made with tabularray package. I include a table similar to yours and another one (better looking IMHO). In this case you probably don't need the siunitx library, but just in case...

\documentclass{article}
\usepackage{lipsum}     % dummy text
\usepackage{tabularray}
\UseTblrLibrary{booktabs,siunitx}

\begin{document}
\lipsum[1]

\begin{table}[ht]\centering
\caption{Original table with \texttt{tabularray}.}
\begin{tblr}
{% format
   vlines,hlines,vline{5}={2}{-}{},
   colspec={ccccccc},
   cell{1}{1}={r=3,c=1}{},   % multirow
   cell{1}{2}={r=1,c=6}{},   % multicolumn
   cell{2}{2,5}={r=1,c=3}{}, % multicolumn
}% content
  & 40 Mod\\
  & method A   &&      & method B \\
  & 1    & 2    & 3    & 1    & 2    & 3 \\
0 & 0.68 & 0.81 & 0.73 & 0.67 & 0.86 & 0.74 \\
1 & 0.93 & 0.87 & 0.90 & 0.93 & 0.89 & 0.91 \\
2 & 0.98 & 0.92 & 0.94 & 0.98 & 0.91 & 0.94 \\
3 & 0.35 & 0.30 & 0.32 & 0.34 & 0.30 & 0.32
\end{tblr}
\end{table}

\lipsum[2]

\begin{table}[ht]\centering
\caption{Alternative table also with \texttt{tabularray}.}
\begin{tblr}
{% format
   colspec={cS[table-format=1.2]
             S[table-format=1.2]
             S[table-format=1.2]
             S[table-format=1.2]
             S[table-format=1.2]
             S[table-format=1.2]},
   cell{1}{1}={r=3,c=1}{},   % multirow
   cell{1}{2}={r=1,c=6}{},   % multicolumn
   cell{2}{2,5}={r=1,c=3}{}, % multicolumn
}% content
\toprule
& {{{40 Mod}}}\\
\cmidrule[lr]{2-7}
& {{{method A}}} & & & {{{method B}}} \\
\cmidrule[lr]{2-4} \cmidrule[lr]{5-7}
& {{{1}}} & {{{2}}} & {{{3}}}& {{{1}}} & {{{2}}} & {{{3}}} \\
\midrule
0 & 0.68 & 0.81 & 0.73 & 0.67 & 0.86 & 0.74 \\
1 & 0.93 & 0.87 & 0.90 & 0.93 & 0.89 & 0.91 \\
2 & 0.98 & 0.92 & 0.94 & 0.98 & 0.91 & 0.94 \\
3 & 0.35 & 0.30 & 0.32 & 0.34 & 0.30 & 0.32 \\
\bottomrule
\end{tblr}
\end{table}
\end{document}

enter image description here

5

Here's a solution that uses a tabular environment, the line-drawing macros of the booktabs package, and no vertical lines.

enter image description here

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

\begin{document}

\begin{tabular}{@{} l cccccc @{}}
\toprule
& \multicolumn{6}{c@{}}{40 Mod}\\
\cmidrule(l){2-7}
& \multicolumn{3}{c}{Method A} & \multicolumn{3}{c@{}}{Method B} \\
\cmidrule(lr){2-4} \cmidrule(l){5-7}
& 1 & 2 & 3 & 1 & 2 & 3 \\
\midrule
0 & 0.68 & 0.81 & 0.73 & 0.67 & 0.86 & 0.74 \\
1 & 0.93 & 0.87 & 0.90 & 0.93 & 0.89 & 0.91 \\
2 & 0.98 & 0.92 & 0.94 & 0.98 & 0.91 & 0.94 \\
3 & 0.35 & 0.30 & 0.32 & 0.34 & 0.30 & 0.32 \\
\bottomrule
\end{tabular}

\end{document}
5

\multirow does nothing useful.

\documentclass{article}
\usepackage{array}

\begin{document}

\begin{tabular}{|c|c|c|c||c|c|c|}
\hline
  & \multicolumn{6}{c|}{40 Mod}\\
\cline{2-7}
     &  \multicolumn{3}{c||}{method A}  &  \multicolumn{3}{c|}{method B} \\
\cline{2-7}
     &  1 & 2 & 3 & 1 & 2 & 3 \\
\hline
0 & 0.68 & 0.81 & 0.73 & 0.67 & 0.86 & 0.74 \\
1 & 0.93 & 0.87 & 0.90 & 0.93 & 0.89 & 0.91 \\
2 & 0.98 & 0.92 & 0.94 & 0.98 & 0.91 & 0.94 \\
3 & 0.35 & 0.30 & 0.32 & 0.34 & 0.30 & 0.32 \\
\hline
\end{tabular}

\end{document}

enter image description here

Now ask yourself what the vertical rules are doing there. The answer is that they simply hinder reading the table.

\documentclass{article}
\usepackage{array,booktabs,siunitx}

\begin{document}

\begin{tabular}{
  @{}
  r
  *{3}{S[table-format=1.2]}
  c
  *{3}{S[table-format=1.2]}
  @{}
}
\toprule
  & \multicolumn{7}{c}{40 Mod} \\
\cmidrule{2-8}
  & \multicolumn{3}{c}{method A} && \multicolumn{3}{c}{method B} \\
\cmidrule(lr){2-4} \cmidrule(l){6-8}
  &  {1} & {2} & {3} && {1} & {2} & {3} \\
\midrule
0 & 0.68 & 0.81 & 0.73 && 0.67 & 0.86 & 0.74 \\
1 & 0.93 & 0.87 & 0.90 && 0.93 & 0.89 & 0.91 \\
2 & 0.98 & 0.92 & 0.94 && 0.98 & 0.91 & 0.94 \\
3 & 0.35 & 0.30 & 0.32 && 0.34 & 0.30 & 0.32 \\
\bottomrule
\end{tabular}

\end{document}

The dummy column takes the place of your double rule.

enter image description here

4
  • 1
    +1 for "Now ask yourself what the vertical rules are doing". :-)
    – Mico
    Feb 24 at 15:21
  • The vertical lines look useful to me. They help you separate the method A results from the method B results.
    – Simd
    Feb 25 at 11:16
  • @Simd Centuries of table design (and all four answers to your question) suggest that some whitespace is better than a vertical rule at separating the two methods.
    – Teepeemm
    Feb 25 at 14:48
  • @Teepeemm I understand. But not to me.
    – Simd
    Feb 25 at 16:00
4

Here is a solution with {NiceTabular} of nicematrix. With that environment, you merge rows and columns with the command \Block. Then, the vertical rules (specified by | in the preamble) and the horizontal rules (specified by \Hline) respect those blocks.

\documentclass{article}
\usepackage{nicematrix}

\begin{document}

\begin{NiceTabular}{|c|c|c|c||c|c|c|}
\Hline
 \Block{3-1}{} & \Block{1-6}{40 Mod}\\
\Hline 
     &  \Block{1-3}{method A}  &&& \Block{1-3}{method B} \\
\Hline
     &  1 & 2 & 3 & 1 & 2 & 3 \\
\Hline
0 & 0.68 & 0.81 & 0.73 & 0.67 & 0.86 & 0.74 \\
1 & 0.93 & 0.87 & 0.90 & 0.93 & 0.89 & 0.91 \\
2 & 0.98 & 0.92 & 0.94 & 0.98 & 0.91 & 0.94 \\
3 & 0.35 & 0.30 & 0.32 & 0.34 & 0.30 & 0.32 \\
\Hline
\end{NiceTabular}

\end{document}

You need several compilations (because nicematrix uses PGF/Tikz nodes under the hood).

Output of the above code

However, I prefer a design in the spirit of booktabs (see answer of Juan Castaño).

You must log in to answer this question.

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