複数列を使用すると行が欠落するのはなぜですか?

複数列を使用すると行が欠落するのはなぜですか?

健康列と合計列の間に線がありません

\documentclass{article}
\usepackage[table]{xcolor}
\usepackage{multirow}
\usepackage{makecell}
\begin{document}
\begin{table}
\centering
\begin{tabular}{|c|c|cc|c|c|} 
\hline
& & \multicolumn{2}{c}{BMI} & \\ 
\multirow{-2.5}{*}{\makecell{Activity level}} & 
\multirow{-2.5}{*}{\makecell{Resting heart rate}} & 
{Unhealthy} & {Healthy} & \multirow{-2.5}{*}{\makecell{Total}} \\
\hline
Inactive & Normal   & 9  & 13 & 22\\ 
         & Abnormal & 16 & \cellcolor{pink}8 & 24\\
Active   & Normal   & 3  & 28 & 31 \\ 
         & Abnormal & \cellcolor{gray}6 & \cellcolor{gray}17 & 23 \\ 
\hline
Total    &          & 34 & 56 & \textbf{100} \\ 
\hline
\end{tabular}  
\end{table}
\end{document}

ここに画像の説明を入力してください

答え1

あなたは観察します、

健康列と合計列の間に線がありません

交換する必要があります

\multicolumn{2}{c}{BMI}

\multicolumn{2}{c|}{BMI}

補遺: コードに多くの不要な部分があり、さらに悪いことに、表が読みにくくなっています。\begin{tabular}{|c|c|cc|c|c|}表には 6 列ではなく 5 列が含まれているため、 があることは自信を持てません。下の最初の表で、最も差し迫った問題をどのように修正しようとしたかを見てください。私自身の意見としては、この表が魅力的または魅力的だとは言えません。2 番目の表では、すべての縦線がなくなり、テキスト列は中央揃えではなく左揃えになっています。

ここに画像の説明を入力してください

\documentclass{article}
\usepackage[table]{xcolor}
\usepackage{multirow,makecell}

%% for the second table:
\usepackage{booktabs,siunitx}
\usepackage[skip=0.333\baselineskip]{caption}

\begin{document}
\begin{table}
\centering
\caption{Dreadful}
\begin{tabular}{|c|c|cc|c|} 
\hline
\multirow{2}{*}{Activity level} & 
\multirow{2}{*}{Resting heart rate} & 
\multicolumn{2}{c|}{BMI} & 
\multirow{2}{*}{Total}\\ 
& & Unhealthy & Healthy &  \\
\hline
Inactive & Normal   & 9  & 13 & 22\\ 
         & Abnormal & 16 & \cellcolor{pink}8 & 24\\
Active   & Normal   & 3  & 28 & 31 \\ 
         & Abnormal & \cellcolor{gray}6 & \cellcolor{gray}17 & 23 \\ 
\hline
Total    &          & 34 & 56 & \textbf{100} \\ 
\hline
\end{tabular}  

\bigskip
\caption{Better}
\begin{tabular}{@{} llccc @{}} 
\toprule
Activity level & Resting heart rate & 
\multicolumn{2}{c}{BMI} & Total\\ 
\cmidrule{3-4}
& & Unhealthy & Healthy &  \\
\midrule
Inactive & Normal   & 9  & 13 & 22\\ 
         & Abnormal & 16 & \cellcolor{pink}8 & 24\\
\addlinespace
Active   & Normal   & 3  & 28 & 31 \\ 
         & Abnormal & \cellcolor{gray}6 & \cellcolor{gray}17 & 23 \\ 
\addlinespace
Total    &          & 34 & 66 & \textbf{100} \\ 
\bottomrule
\end{tabular}  
\end{table}
\end{document}

関連情報