5

I need to generate the following table. I wrote this code and got the output in fig 1.

\documentclass{article}
\usepackage{multirow}
\usepackage{array}
\begin{document}
    \begin{center}

    \begin{tabular}{|c|c|c|}
        \hline

        \multicolumn{3}{|c|}{Performance measure}\\ \hline
        evaluation metric&Proposed method&traditional method\\ \hline
        DC&0.0019&0.0021 \\ \hline
        JS&0.9975&0.9916\\ \hline
        DSC&0.9987&0.9958\\ \hline


    \end{tabular}
\end{center}
\end{document}

fig 1. enter image description here

but I need to generate the table in fig 2.

enter image description here

Please help me to generate the table in fig 2 in latex

8

Here's a slightly different solution, this one using booktabs. I know this does away with some of OP's formatting, but I also know many of us subscribe to the notion that vertical rules ruin tables.

\documentclass{article}
\usepackage{booktabs}
\begin{document}

\begin{tabular}{*{5}{c}}
    \toprule
    & \multicolumn{3}{c}{Performance measure} & \\ \cmidrule(lr){2-4}
    Paper title & Evaluation metric & Proposed method & Traditional method & Image type \\ \midrule
    & DC & 0.0019 & 0.0021 \\
    & JS & 0.9975 & 0.9916 \\
    & DSC & 0.9987 & 0.9958 \\
    \bottomrule
  \end{tabular}

\end{document}

enter image description here

(Although if OP goes this route, s/he may wish to redesign some elements of the table for clarity of data.)

  • 1
    Does your proposed method allow for automatic line-breaking inside cells? – Mico May 5 '17 at 9:38
  • No, but I'm also a \footnotesize tablemaker. @Zarko's answer addresses this, however. – Richard May 5 '17 at 12:22
6

Edit: In the first attempt I miss one column, so I decide to delete this version of answer ... the second version is:

enter image description here

    \documentclass{article}
    \usepackage{booktabs, tabularx}
    \newcolumntype{C}{>{\centering\let\newline\\\arraybackslash\hspace{0pt}}X}

    \begin{document}
        \begin{center}
    \begin{tabularx}{\linewidth}{*{5}{C}}
            \toprule    
        &   \multicolumn{3}{c}{Performance measure}                         &               \\ 
            \cmidrule(lr){2-4}
    Paper\newline title 
        &   evaluation metric   &   Proposed method &   traditional method  &   image\newline type  \\
        \midrule
        &   DC                  &   0.0019          &   0.0021              &               \\
        &   JS                  &   0.9975          &   0.9916              &               \\
        &   DSC                 &   0.9987          &   0.9958              &               \\
        \bottomrule
    \end{tabularx}
        \end{center}
    \end{document}

Addendum: From question is not clear if the paper title is for all tree rows or for each row separately. In both case it can be expected that paper title is longer than cell width, consequently it would be broken into more lines. In the first case the lines can take vertical space of three rows (using multirow cell), se MWE below:

enter image description here

\documentclass{article}
\usepackage{booktabs, multirow, tabularx}
\newcolumntype{C}{>{\centering\let\newline\\\arraybackslash\hspace{0pt}}X}

\begin{document}
    \begin{center}
    \setlength\tabcolsep{3pt}
\begin{tabularx}{\linewidth}{>{\setlength\hsize{1.8\hsize}}C 
                        *{4}{>{\setlength\hsize{0.8\hsize}}C} C}
        \toprule
    &   \multicolumn{3}{c}{Performance measure}                         &                           \\
        \cmidrule(lr){2-4}
Paper\newline title
    &   evaluation metric   &   Proposed method &   traditional method  &   image\newline type      \\
    \midrule
\multirow{3}{=}{Comparison of image evaluation methods}
    &   DC                  &   0.0019          &   0.0021              &   \multirow{3}{=}{Lena}   \\
    &   JS                  &   0.9975          &   0.9916              &                           \\
    &   DSC                 &   0.9987          &   0.9958              &                           \\
    \bottomrule
\end{tabularx}
    \end{center}
\end{document}
  • Would you plz tell me how to add a paper name in the cell under " Paper title" and under under "Image type" cell? I tried but failed – Hafsa Moontari Ali May 6 '17 at 12:55
  • @HafsaMoontariAli, see addendum to my answer. I added "paper title" and "image name". Also I changed table design by introducing multirow package. and changes column width. – Zarko May 6 '17 at 18:42
5

Or this?

\documentclass{article}
\usepackage{multirow, makecell}
\setcellgapes{4pt}
\usepackage{array}

\begin{document}

    \begin{center}
\sffamily\makegapedcells
    \begin{tabular}{|c|c|c|c|c|}
        \hline
\multirow{3}{*}[-4.4pt]{Paper title} & \multicolumn{3}{|c|}{Performance measure} & \multirow{3}{*}[-4.4pt]{Image type}\\
\cline{2-4}
       & \makecell{Evaluation\\ metric}& \makecell{Proposed\\ method} & \makecell{Traditional\\ method} & \\ \hline
         & DC&0.0019&0.0021 & \\ \hline
         & JS&0.9975&0.9916 & \\ \hline
        & DSC&0.9987&0.9958 & \\ \hline


    \end{tabular}
\end{center}

\end{document} 

enter image description here

3

You need to add the outer columns and use \multirow for the upper outer cells. I also used tabularx instead since it looks like you want equal sized columns.

\documentclass{article}
\usepackage{multirow}
\usepackage{tabularx}
\usepackage{array}
\begin{document}
    \begin{center}
    \begin{tabularx}{\linewidth}{|X|X|X|X|X|}
      \hline
      \multirow{2}{*}{Paper title} &
      \multicolumn{3}{c|}{Performance measure} & 
      \multirow{2}{*}{Image type}\\ \cline{2-4}
      & evaluation metric & Proposed method & traditional method &\\ \hline
      & DC  & 0.0019 & 0.0021 & \\ \cline{2-4}
      & JS  & 0.9975 & 0.9916 & \\ \cline{2-4}
      & DSC & 0.9987 & 0.9958 & \\ \hline
    \end{tabularx}
\end{center}
\end{document}

enter image description here

Second version

Actually it is not needed to have a \multirow in the table head, it is easier to just leave the upper row of the first and last colmns empty and type in the second. To get a paper title spanning more than one row one would need \multirow. I have also used it in the last column.

\documentclass{article}
\usepackage{multirow}
\usepackage{tabularx}
\usepackage{array}
\begin{document}
  \begin{center}
    \begin{tabularx}{\linewidth}{|p{0.25\linewidth}|X|X|X|p{0.2\linewidth}|}
      \hline
      & \multicolumn{3}{c|}{Performance measure} & \\ \cline{2-4}
      \strut\newline Paper title
      & evaluation metric & Proposed method & traditional method & 
      \strut\newline Image type\\ \hline
      \multirow{3}{\linewidth}{A Comparison of new methods for images}
      & DC  & 0.0019 & 0.0021 & 
      \multirow{3}{\linewidth}{Baboon}\\ \cline{2-4}
      & JS  & 0.9975 & 0.9916 & \\ \cline{2-4}
      & DSC & 0.9987 & 0.9958 & \\ \hline
    \end{tabularx}
\end{center}
\end{document}

enter image description here

The two \strut\newlines are used to move Paper Title and Image Type down to the second line. If you want them aligned with the top rows of the Method cells, just remove it.

  • Would you plz tell me how to add a paper name in the cell under " Paper title" and under under "Image type" cell? I tried but failed. – Hafsa Moontari Ali May 6 '17 at 12:55
  • @HafsaMoontariAli; There is a second version adding paper name and image type texts. – StefanH May 7 '17 at 16:14

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.