2

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?

enter image description here

enter image description here`

2
  • 2
    Please never post screenshots of your code. Instead post the code as text, so that is easy to copy and manipulate it. Anyways, you need to replace the column definition in the second \multicolumn macro so that it becomes \multicolumn{2}{c|}{b-c}. Mar 29 at 23:00
  • Actually, all you need is use {c|} instad of {c} in the rightmost \multicolumn. (\multicolumn eats vertical lines.) Mar 30 at 14:43

2 Answers 2

2

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|}{...}.

enter image description here

\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}
2

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}

enter image description here

0

You must log in to answer this question.

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