3

I am using Overleaf to draw a Table that contained multirow cells, I am facing a problem with the right border, there are missing lines, I am using the code below, what I am missing?

\begin{table}[ht!]
\centering
  \caption{Demographic Information}
  \label{tab:dv}
  \scriptsize
\def\arraystretch{}
  \begin{tabular}{|l|l|c|c|}
  \hline\noalign{\smallskip} 
      \multicolumn{2}{|l|}{ Demographic Variables}  & count&   percent(\%)\\  \noalign{\smallskip}\hline\noalign{\smallskip}
    \multirow{2}{*}{Gender} & Male                            & 24 &    60 \\   \cline{2-4} 
                           & Female                & 16 &   40    \\  \cline{2-4} 
                           \\ \noalign{\smallskip}\hline\noalign{\smallskip}
    \multirow{2}{*}{Qualification} &     Bachelor             & 30& 75   \\    \cline{2-4} 
                                    &     Master                 &  10 &    25  \\  \cline{2-4} 
                                    \\ \hline
   \multirow{2}{*}{Specialization } & Computer Engineering                    &  26 &   52  \\   \cline{2-4} 
                                    & Software Engineering                     &  18 &  36  \\     \cline{2-4}    
                                     & Computer Science                     & 2 &4\\        \cline{2-4} 
                                      &   Information Technology                     & 1&   2\\    \cline{2-4}    
                              \\       \hline
 \multirow{2}{*}{Software Experience} & 1-3 years                    &  12  &30  \\      \cline{2-4} 
                                    & 4-6 years                    &  12 &  30\\         \cline{2-4} 
                                     & 7 -10 year                     & 9 & 22.5  \\   \cline{2-4} 
                                     & 11 years or more               & 7 & 17.5  \\ \cline{2-4} 
                            \\ \hline
\multirow{2}{*}{Work Sector} & Private Sector                   &32 &80  \\      \cline{2-4} 

                           & Public Sector                 &  6&    15\\  \cline{2-4} 
                           & Educational Organization                   &2  &5   \\  \cline{2-4} 
                           \\ \hline
                           
 \multirow{2}{*}{Team Size} & 1-5                    &  16  &40  \\      \cline{2-4} 
                                    & 6-10                     &  13 &  30\\         \cline{2-4} 
                                     & 11 -15                      & 5 &    12  \\   \cline{2-4} 
                                     & More than 15                & 5 &    12  \\   \noalign{\smallskip}\hline                
\end{tabular}
\end{table}

The output :

Table output

3
  • you have \cline{2-4} \\ \noalign{\smallskip}\hline\noalign{\smallskip} the \\ after \cline is forcing an empty row with only a cell in the first column. Mar 7, 2022 at 9:55
  • I removed it and the problem is still there
    – Mai
    Mar 7, 2022 at 10:08
  • you could not have removed them all, as that is the fix (see my answer) Mar 7, 2022 at 10:24

3 Answers 3

3

All those \noalign command will disrupt the vertical rules. And you don't want \cline{2-4} to be followed by \hline.

Take your time to visually align entries, so you can better see the data in the source file.

Here are two realizations of the table: my usual rule is that every table using \multirow can be improved by removing it.

Note that \def\arraystretch{} is really wrong.

\documentclass{article}
\usepackage{multirow}
\usepackage{booktabs,siunitx} % for the second realization

\begin{document}

\begin{table}[!htp]
\centering\footnotesize

\caption{Demographic Information}
\label{tab:dv}

\begin{tabular}{|l|l|c|c|}
\hline
\multicolumn{2}{|l|}{Demographic Variables} & count & percent (\%) \\ 
\hline
\multirow{2}{*}{Gender}              & Male                     & 24 & 60 \\
\cline{2-4} 
                                     & Female                   & 16 & 40 \\
\hline
\multirow{2}{*}{Qualification}       & Bachelor                 & 30 & 75 \\
\cline{2-4} 
                                     & Master                   & 10 & 25 \\
\hline
\multirow{4}{*}{Specialization}      & Computer Engineering     & 26 & 52 \\
\cline{2-4} 
                                     & Software Engineering     & 18 & 36 \\
\cline{2-4}    
                                     & Computer Science         &  2 &  4 \\
\cline{2-4} 
                                     & Information Technology   &  1 &  2 \\
\hline
\multirow{4}{*}{Software Experience} & 1--3 years               & 12 & 30 \\
\cline{2-4} 
                                     & 4--6 years               & 12 & 30 \\
\cline{2-4} 
                                     & 7--10 year               &  9 & 22.5 \\
\cline{2-4} 
                                     & 11 years or more         &  7 & 17.5 \\
\hline
\multirow{3}{*}{Work Sector}         & Private Sector           & 32 & 80 \\
\cline{2-4}
                                     & Public Sector            &  6 & 15 \\
\cline{2-4} 
                                     & Educational Organization &  2 &  5 \\
\hline
                           
\multirow{4}{*}{Team Size}           & 1--5                     & 16 & 40 \\
\cline{2-4}
                                     & 6--10                    & 13 & 30 \\
\cline{2-4}
                                     & 11--15                   &  5 & 12 \\
\cline{2-4}
                                     & More than 15             &  5 & 12 \\
\hline                
\end{tabular}
\end{table}

\begin{table}[!htp]
\centering

\caption{Demographic Information}
\label{tab:dv-better}

\begin{tabular}{@{} l l S[table-format=2.0] S[table-format=2.1] @{}}
\toprule
\multicolumn{2}{@{}l}{Demographic Variables} & {count} & {percent (\%)} \\ 
\midrule
\textit{Gender}
& Male                     & 24 & 60 \\
& Female                   & 16 & 40 \\
\midrule
\textit{Qualification}
& Bachelor                 & 30 & 75 \\
& Master                   & 10 & 25 \\
\midrule
\textit{Specialization}
& Computer Engineering     & 26 & 52 \\
& Software Engineering     & 18 & 36 \\
& Computer Science         &  2 &  4 \\
& Information Technology   &  1 &  2 \\
\midrule
\textit{Software Experience}
& 1--3 years               & 12 & 30 \\
& 4--6 years               & 12 & 30 \\
& 7--10 year               &  9 & 22.5 \\
& 11 years or more         &  7 & 17.5 \\
\midrule
\textit{Work Sector}
& Private Sector           & 32 & 80 \\
& Public Sector            &  6 & 15 \\
& Educational Organization &  2 &  5 \\
\midrule
\textit{Team Size}
& 1--5                     & 16 & 40 \\
& 6--10                    & 13 & 30 \\
& 11--15                   &  5 & 12 \\
& More than 15             &  5 & 12 \\
\bottomrule
\end{tabular}
\end{table}

\end{document}

enter image description here

1
  • thank you very mutch
    – Mai
    Mar 8, 2022 at 12:56
3

You should never have \\ after \cline: that forces an empty one-cell row. (It would be easier to see if you always places \\ at the end of the line in the source file.)

Your table would look a lot better without the vertical rules, but...

enter image description here

\documentclass{article}

\usepackage{array,multirow}

\begin{document}

\begin{table}[htp]
\centering
  \caption{Demographic Information}
  \label{tab:dv}
  \scriptsize
\def\arraystretch{1}
\setlength\extrarowheight{2pt}
  \begin{tabular}{|l|l|c|c|}
  \hline\noalign{\smallskip} 
      \multicolumn{2}{|l|}{ Demographic Variables}  & count&   percent(\%)\\
  \noalign{\smallskip}\hline
%\noalign{\smallskip}
    \multirow{2}{*}{Gender} & Male                            & 24 &    60 \\   \cline{2-4} 
                           & Female                & 16 &   40    \\ 
% \cline{2-4} 
%                           \\
% \noalign{\smallskip}
\hline
% \noalign{\smallskip}
    \multirow{2}{*}{Qualification} &     Bachelor             & 30& 75   \\    \cline{2-4} 
                                    &     Master                 &  10 &    25  \\  \cline{2-4} 
%                                    \\
 \hline
   \multirow{2}{*}{Specialization } & Computer Engineering                    &  26 &   52  \\   \cline{2-4} 
                                    & Software Engineering                     &  18 &  36  \\     \cline{2-4}    
                                     & Computer Science                     & 2 &4\\        \cline{2-4} 
                                      &   Information Technology                     & 1&   2\\    \cline{2-4}    
%                              \\ 
      \hline
 \multirow{2}{*}{Software Experience} & 1-3 years                    &  12  &30  \\      \cline{2-4} 
                                    & 4-6 years                    &  12 &  30\\         \cline{2-4} 
                                     & 7 -10 year                     & 9 & 22.5  \\   \cline{2-4} 
                                     & 11 years or more               & 7 & 17.5  \\
%  \cline{2-4} 
%                            \\
 \hline
\multirow{2}{*}{Work Sector} & Private Sector                   &32 &80  \\      \cline{2-4} 

                           & Public Sector                 &  6&    15\\  \cline{2-4} 
                           & Educational Organization                   &2  &5   \\
%  \cline{2-4} 
%                           \\
 \hline
                           
 \multirow{2}{*}{Team Size} & 1-5                    &  16  &40  \\      \cline{2-4} 
                                    & 6-10                     &  13 &  30\\         \cline{2-4} 
                                     & 11 -15                      & 5 &    12  \\   \cline{2-4} 
                                     & More than 15                & 5 &    12  \\
%   \noalign{\smallskip}
\hline                
\end{tabular}
\end{table}


\end{document}

Apart from adding \extrarowheight to keep text away from the rules, this is just commenting out \\ and \noalign

1
  • thank you very mutch
    – Mai
    Mar 8, 2022 at 12:56
2

A simple code (using tabularray package) without your problem and where cell contents are "jailed" between lines ...

\documentclass{article}
\usepackage{tabularray}
\UseTblrLibrary{siunitx}

\begin{document}
    \begin{table}[htp]
    \centering
\caption{Demographic Information}
\label{tab:dv}
  \small
\begin{tblr}{hlines, vlines,
             colspec = {l l 
                        S[table-format=2.0]
                        S[table-format=2.1]
                        },
             }
\SetCell[c=2]{c}    Demographic Variables   
    &               & {{{count}}} 
                            & {{{percent(\%)}}} \\
\SetCell[r=2]{h}    Gender  
    & Male          & 24    &   60          \\
    & Female        & 16    &   40          \\
\SetCell[r=2]{h}    Qualification
    & Bachelor      & 30    &   75          \\
    & Master        &  10   &   25          \\ 
\SetCell[r=4]{h}    Specialization
    & Computer Engineering      &  6    & 52    \\ 
    & Software Engineering      & 18    & 36    \\
    & Computer Science          &  2    &  4    \\        
    & Information Technology    &  1    &  2    \\
\SetCell[r=4]{h}    Software Experience
    & 1-3 years                 & 12    & 30    \\ 
    & 4-6 years                 & 12    & 30    \\  
    & 7 -10 year                &  9    & 22.5  \\  
    & 11 years or more          &  7    & 17.5  \\
\SetCell[r=3]{h}    Work Sector
    & Private Sector            & 32    & 80    \\      
    & Public Sector             &  6    & 15    \\
    & Educational Organization  &  2    &  5    \\
\SetCell[r=4]{h}    Team Size
    &  1 -- 5                   & 16    & 40    \\
    &  6 -- 10                  & 13    & 30    \\         
    & 11 -- 15                  &  5    & 12    \\  
    & More than 15              &  5    & 12    \\
\end{tblr}
    \end{table}
\end{document}

enter image description here

However as in other answers are suggested: without vertical lines and horizontal lines only between multi row cells:

\documentclass{article}
\usepackage{tabularray}
\UseTblrLibrary{booktabs, siunitx}

\begin{document}
    \begin{table}[htp]
    \centering
\caption{Demographic Information}
\label{tab:dv}
  \small
\begin{tblr}{colspec = {l l 
                        S[table-format=2.0]
                        S[table-format=2.1]
                        },
             }
    \toprule
\SetCell[c=2]{c}    Demographic Variables   
    &               & {{{count}}} 
                            & {{{percent(\%)}}} \\
    \midrule
\SetCell[r=2]{h}    Gender  
    & Male          & 24    &   60          \\
    & Female        & 16    &   40          \\
    \midrule[dashed]
\SetCell[r=2]{h}    Qualification
    & Bachelor      & 30    &   75          \\
    & Master        &  10   &   25          \\ 
    \midrule[dashed]
\SetCell[r=4]{h}    Specialization
    & Computer Engineering      &  6    & 52    \\ 
    & Software Engineering      & 18    & 36    \\
    & Computer Science          &  2    &  4    \\        
    & Information Technology    &  1    &  2    \\
    \midrule[dashed]
\SetCell[r=4]{h}    Software Experience
    & 1-3 years                 & 12    & 30    \\ 
    & 4-6 years                 & 12    & 30    \\  
    & 7 -10 year                &  9    & 22.5  \\  
    & 11 years or more          &  7    & 17.5  \\
    \midrule[dashed]
\SetCell[r=3]{h}    Work Sector
    & Private Sector            & 32    & 80    \\      
    & Public Sector             &  6    & 15    \\
    & Educational Organization  &  2    &  5    \\
    \midrule[dashed]
\SetCell[r=4]{h}    Team Size
    &  1 -- 5                   & 16    & 40    \\
    &  6 -- 10                  & 13    & 30    \\         
    & 11 -- 15                  &  5    & 12    \\  
    & More than 15              &  5    & 12    \\
    \bottomrule
\end{tblr}
    \end{table}
\end{document}

enter image description here

If you not liked dashed lines, delete \midrule' option [dashed].

1
  • thank you very mutch
    – Mai
    Mar 8, 2022 at 12:56

You must log in to answer this question.

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