1

Lines are missing between healthy and total column

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

enter image description here

Mico
  • 506,678
Ng123
  • 85
  • this is identical to your last question (and please markup the code section this time) – David Carlisle Mar 26 '20 at 21:58
  • what do you mean markup? @DavidCarlisle and yes, however I do have the right code now – Ng123 Mar 26 '20 at 22:17
  • do not post duplicate questions. By markup I meant, as explained last time use the {} button so that your latex code appears in teh grey box with line endings and \\ displayed correctly. – David Carlisle Mar 26 '20 at 22:25
  • I've taken the liberty of editing your code to make it compilable. – Mico Mar 26 '20 at 22:35
  • Off-topic: There's an arithmetic error in your table. The number 56 in the bottom row should be 66... – Mico Mar 26 '20 at 22:44

1 Answers1

2

You observe,

Lines are missing between healthy and total column

You must replace

\multicolumn{2}{c}{BMI}

with

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

Addendum: There's a lot of cruft in your code; worse, the table isn't all that readable. It's not confidence-inspiring that you have \begin{tabular}{|c|c|cc|c|c|}, since the table contains 5, not 6, columns. Take a look at how I tried to fix the most pressing issues in the first table below. Speaking for myself, I can't say I find this table attractive or appealing. The second table does away with all vertical lines and uses left-alignment rather than centering for the text columns.

enter image description here

\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}
Mico
  • 506,678