1

I have a table that I need to put in a paper. The horizontal and vertical lines are broken lines but my supervisor asked me to have closed lines. I am not able to fix it.

\usepackage{tabularx}

  \begin{table}[h]
  \centering
  \caption{my table with broken lines}
  \resizebox{\textwidth}{!}{%
\begin{tabular}{@{}|c|c|c|c|c|c|@{}}
\toprule
\multirow{3}{*}{A}             & \multirow{3}{*}{B}                 & \multicolumn{4}{|c|}{M}                                                                                                               \\ \cmidrule(l){3-6} 
                                   &                                & \multicolumn{2}{|c|}{C}                                        & \multicolumn{2}{|c|}{D}                                          \\ \cmidrule(l){3-6} 
                                   &                                & \multicolumn{1}{|c|}{e}            & \multicolumn{1}{|c|}{f} & \multicolumn{1}{|c|}{e}            & \multicolumn{1}{|c|}{f} \\ \midrule
\multicolumn{1}{|c|}{1}  & \multicolumn{1}{|c|}{a}      & \multicolumn{1}{|c|}{\multirow{4}{*}{100}} & \multicolumn{1}{|c|}{91.02}    & \multicolumn{1}{|c|}{\multirow{4}{*}{90}} & \multicolumn{1}{|c|}{209.2}    \\ \cmidrule(r){1-2} \cmidrule(lr){4-4} \cmidrule(l){6-6} 
\multicolumn{1}{|c|}{2} & \multicolumn{1}{|c|}{b}  & \multicolumn{1}{|c|}{}                   & \multicolumn{1}{|c|}{133.83}   & \multicolumn{1}{|c|}{}                   & \multicolumn{1}{|c|}{239.66}   \\ \cmidrule(r){1-2} \cmidrule(lr){4-4} \cmidrule(l){6-6} 
\multicolumn{1}{|c|}{3}    & \multicolumn{1}{|c|}{b} & \multicolumn{1}{|c|}{}                   & \multicolumn{1}{|c|}{159.73}   & \multicolumn{1}{|c|}{}                   & \multicolumn{1}{|c|}{373.47}   \\ \cmidrule(r){1-2} \cmidrule(lr){4-4} \cmidrule(l){6-6} 
4                              & \multicolumn{1}{|c|}{c}  & \multicolumn{1}{c|}{}                   & \multicolumn{1}{|c|}{144.1}    & \multicolumn{1}{|c|}{}                   & 317.01                        \\ \bottomrule
\end{tabular}
}
  \label{tbl:lbl1}
\end{table}

It appears like this. enter image description here

3
  • 1
    Horizontal rules from booktabs package doesn't work well with vertical lines. replace them with \hline or cline{...} accordingly. – Zarko Aug 17 '20 at 6:02
  • I addition to the before mentioned booktabs incompatibility, please also stay away from resizebox. This will only result in I consistent font sizes. Also, the \multicolumn{1}{|c|} commands in the first column are redundant since your column is already centered. – leandriis Aug 17 '20 at 6:06
  • @Zarko I was just about to ask you to put your comment as answer because that fixed my problem. Now I see that you put an answer I will accept it. Thanks a lot!! – hope Aug 17 '20 at 6:22
2

Like this?

enter image description here

\documentclass{article}
\usepackage{makecell, multirow}

\begin{document}
  \begin{table}[h]
  \centering
  \setcellgapes{3pt}
  \makegapedcells
\caption{my table with broken lines}
  \label{tbl:lbl1}
\begin{tabular}{|*{6}{c|}}
    \Xhline{1pt}
\multirow{3.4}{*}{A}
    &   \multirow{3.4}{*}{B}
        &   \multicolumn{4}{c|}{M}                  \\
    \cline{3-6}
    &   &   \multicolumn{2}{c|}{C}
                &   \multicolumn{2}{c|}{D}          \\
    \cline{3-6}
    &   & e & f & e & f                             \\
    \hline
1   & a & \multirow{4.5}{*}{100}
            &  91.02    & \multirow{4.5}{*}{90}   
                                        & 209.2    \\
    \cline{1-2} \cline{4-4} \cline{6-6}
2   & b &   &  133.83   &               &  239.66   \\
    \cline{1-2} \cline{4-4} \cline{6-6}
3   & b &   & 159.73    &              & 373.47    \\
        \cline{1-2} \cline{4-4} \cline{6-6}
4   & c &   & 144.1     &              & 317.01    \\
    \Xhline{1pt}
\end{tabular}
    \end{table}
\end{document}

or if you like to have table wide as \textwidth, than you can use tabularx table environment (not recommended):

enter image description here

\documentclass{article}
\usepackage{makecell, multirow, tabularx}
\newcolumntype{C}{>{\centering\arraybackslash}X}

\begin{document}
  \begin{table}[h]
  \centering
  \setcellgapes{3pt}
  \makegapedcells
\caption{my table with broken lines}
      \label{tbl:lbl1}
\begin{tabularx}{\linewidth}{|*{6}{C|}}
    \Xhline{1pt}
\multirow{4}{*}{A}             
    &   \multirow{4}{*}{B}                 
        &   \multicolumn{4}{c|}{M}                  \\
    \cline{3-6}
    &   &   \multicolumn{2}{c|}{C} 
                &   \multicolumn{2}{c|}{D}          \\ 
    \cline{3-6}
    &   & e & f & e & f                             \\
    \hline
1   & a & \multirow{5.5}{=}{\centering    100}
            &  91.02    & \multirow{5.5}{=}{\centering 90}   
                            & 209.2    \\
    \cline{1-2} \cline{4-4} \cline{6-6}
2   & b &   &  133.83   &   &  239.66   \\
    \cline{1-2} \cline{4-4} \cline{6-6}
3   & b &   & 159.73    &   & 373.47    \\
        \cline{1-2} \cline{4-4} \cline{6-6}
4   & c &   & 144.1     &   & 317.01    \\
    \Xhline{1pt}
\end{tabularx}
    \end{table}
\end{document}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.