I am trying to nest multicolumn in a multirow but my code doesn't properly close the table in the first row. How to fix this?
2 Answers
First off, it's not clear why you choose an very small column width for all five columns. Second, since line-breaking within cells doesn't seem to be needed (or even permitted), I wouldn't use a column type that permits line breaking and use the w
column type instead. Third, the missing vertical line arises because you use \multicolumn{2}{c}{...}
instead of \multicolumn{2}{c|}{...}
.
\documentclass{article}
\usepackage{array} % for 'm' and 'w' column types
\usepackage{multirow}
\usepackage{newtxtext,newtxmath} % optional
\renewcommand\thetable{\Roman{table}} % optional
\begin{document}
\setcounter{table}{4} % just for this example
\begin{table}[h]
\centering
\caption{Dummy table}
\begin{tabular}{| *{5}{wc{3mm}} |} % choose suitable column types/widths
\hline
\multirow{2}{*}{a}
& \multicolumn{2}{c }{b-c}
& \multicolumn{2}{c|}{b-c} \\ % <- note the "|" symbol
& b2 & c2 & d2 & e2 \\ \hline
r & 1 & 2 & 3 & 4 \\ \hline
\end{tabular}
\end{table}
\end{document}
tabularray
is much simpler.
\documentclass{article}
\usepackage{tabularray}
\begin{document}
\begin{table}
\caption{title}
\centering
\begin{tblr}
{
colspec = {Q[c,m]Q[c,m]Q[c,m]Q[c,m]Q[c,m]},
hline{1,3,Z} = {},
vline{1,Z} = {},
cell{1}{2,4} = {c=2}{},
cell{1}{1} = {r=2}{},
}
a & b-c & & b-c & \\
& b2 & c2 & d2 & e2 \\
r & 1 & 2 & 3 & 4 \\
\end{tblr}
\end{table}
\end{document}
\multicolumn
macro so that it becomes\multicolumn{2}{c|}{b-c}
.