1

As pointed out here it is important to use

\multicolumn{3}{|l|}{}

in the following line of multicolumn.

Nevertheless I am struggling around with the same issue (unconnected vertical lines) and can't find a solution for it:

enter image description here

Here is how far I got. Any ideas would be great.

\usepackage{booktabs}
\usepackage{multirow}
\usepackage{makecell}

{\renewcommand{\arraystretch}{2}%
\begin{table}
\centering
\begin{tabular}{@{}ll|cc@{}} \toprule
\multicolumn{2}{c|}{\multirow{2}{*}{}} & \multicolumn{2}{c}{Text} \\
\cmidrule(r){3-4}
\multicolumn{2}{c|}{} & A & B\\ \midrule
\multicolumn{1}{c|}{\multirow{2}{*}{\thead{Text1 and \\ Text2}}} & C & \thead{1\\and 1}& 2 \\
\multicolumn{1}{c|}{} & D & 3 & \thead{4\\ and 4} \\
\bottomrule
\end{tabular}
\end{table}} \quad
  • The line between Text1andText2 and C / D maybe should stay as it is. – KLJ Dec 4 '18 at 17:57
  • 5
    The issue is not the same as the linked question. The gaps you see is because you are using vertical rules with booktabs. The booktabs documentation emphasizes "Never, ever use vertical rules". If you replace the \toprule, \bottomrule and \midrule by \hline the gaps will close. Better to remove the vertical rules, though. – Phelype Oleinik Dec 4 '18 at 17:59
  • 1
    please look at the documentation for booktabs, the package author makes it clear he thinks vertical rules are evil and by design the package makes them unusable – David Carlisle Dec 4 '18 at 18:23
1

Booktabs sets a vertical padding above and below its rules. You can set this padding to 0, and enjoy the other functionalities. Anyway, with \arraystretch set to 2, do you really need it? If necessary, you can replace it with the \setcellgapes command from makecell. I took the opportunity to slightly simplify the code of your table, with the \multirowthead command:

\documentclass{article}
\usepackage{booktabs}
\usepackage{multirow}
\usepackage{makecell}

\begin{document}

\begin{table}
\renewcommand{\arraystretch}{2}%
\centering
\aboverulesep = 0pt
\belowrulesep = 0pt
\begin{tabular}{@{}ll|cc@{}} \toprule
\multicolumn{2}{c|}{\multirow{2}{*}{}} & \multicolumn{2}{c}{Text} \\
\cmidrule(r){3-4}
\multicolumn{2}{c|}{} & A & B\\ \midrule
\multicolumn{1}{c|}{\multirowthead{2}[-1ex]{Text1 and \\ Text2}} & C & \thead{1\\and 1}& 2 \\
\multicolumn{1}{c|}{} & D & 3 & \thead{4\\ and 4} \\
\bottomrule
\end{tabular}
\end{table} \quad

\end{document} 

enter image description here

  • Thanks for the support and simplification as well! – KLJ Dec 5 '18 at 7:31
  • Interesting to see that there is no "multicolumnthead" – KLJ Dec 5 '18 at 7:51
  • @KLJ: Yes, that's a mystery to me. – Bernard Dec 5 '18 at 9:31
1

As mentioned in the booktabs documentation (and with that in the comments above) I tried it without the vertical lines and have to admit that it looks better now:

enter image description here

\documentclass{article}
\usepackage{booktabs}
\usepackage{multirow}
\usepackage{makecell}

\begin{document}    

{\renewcommand{\arraystretch}{2}%
\begin{table}
\centering
\begin{tabular}{@{}ccc@{}}
\toprule
& \multicolumn{2}{c}{Text} \\
\cmidrule(r){2-3}
\thead{Text1 and \\ Text2} & A & B\\
\midrule
C & \thead{1\\and 1}& 2 \\
D & 3 & \thead{4\\ and 4} \\
\bottomrule
\end{tabular}
\end{table}} \quad

\end{document} 
  • often it also (if space permits) looks better if you space it out, aka add more horizontal space – daleif Dec 5 '18 at 8:59
  • That is true. I my case it doesn't. But if other (also) wonder how to add horizontal spcae: {\setlength{\tabcolsep}{2em} TABLE } – KLJ Dec 5 '18 at 12:01
  • That is not a good way, this evenly added space everywhere, not really what we want. Often we want space between columns. I have a tendency to introduce extra columns just for this. – daleif Dec 5 '18 at 12:39

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.