2

I've been struggling with table editing, so I started using a website to generate tables in LaTeX. However, whenever I'm using multirow and borders, things get a little tricky. I get a discontinuous line along my column.

As a test, I'm using this:

\begin{table}[]
\centering
\caption{My caption}
\label{my-label}
\begin{tabular}{@{}c|cc@{}}
Test               & a & b \\ \midrule
\multirow{2}{*}{x} & 1 & 2 \\ \cmidrule(l){2-3} 
               & 3 & 4
\end{tabular}
\end{table}

This is the result:

test table

I'm using TexPortable with MiKTeX 2.9.6210 and Texmaker 4.5.

Moriambar
  • 11,466
This Guy
  • 121

2 Answers2

4

This is related to the padding around horizontal lines in booktabs (the lengths \aboverulesep and \belowrulesep). Vertical rules should not be used with booktabs in general (this principle suffers exceptions). A workaround consists in setting them to 0 and replacing them with more or less equivalent lengths added at the top and bottom of cells with the tools from makecell.

\documentclass{article}
\usepackage{booktabs, multirow, array, makecell, caption}

\begin{document}

\begin{table}[!htb]
\centering
\setlength\aboverulesep{0pt}\setlength\belowrulesep{0pt}
\setcellgapes{3pt}\makegapedcells
\caption{My caption}
\label{my-label}
\begin{tabular}{@{}c|cc@{}}
Test & a & b \\ \midrule
\multirow{2}{*}{x} & 1 & 2 \\ \addlinespace[-0.03em]\cmidrule(l){2-3}
               & 3 & 4
\end{tabular}
\end{table}

\end{document} 

enter image description here

Bernard
  • 271,350
  • I've tried that and it worked on the vertical line, but the horizontal line is still discontinuous, here. Thank you! – This Guy Apr 26 '17 at 09:18
  • 1
    Do you mean the short line between 2nd and 3rd row? I thought it was there purposely. The responsible is the (l) optional argument of \cmidrule. Just remove it. – Bernard Apr 26 '17 at 09:25
1

If you want vertical lines compatible with the horizontal rules of booktabs, you should use {NiceTabular} of nicematrix.

\documentclass{article}
\usepackage{booktabs, caption, nicematrix}

\begin{document}

\begin{table}[!htb] \centering \caption{My caption} \label{my-label} \begin{NiceTabular}{@{}c|cc@{}}[cell-space-limits=3pt] Test & a & b \ \midrule \Block{2-1}{x} & 1 & 2 \ \cmidrule(l){2-3} & 3 & 4 \end{NiceTabular} \end{table}

\end{document}

Output of the above code

F. Pantigny
  • 40,250