# Latex Multiple Column and Row [duplicate]

I want to combine a multiple row and a column table in LaTeX format yet I'm not able to do.

Here is what I want in latex template.

Can anyone help me with this? Thank you.

• Welcome to TeX.SX! Try using \multirow{2}{*}{Mapping Method} & \multicolumn{4}{c}{SVM (\%)} & ... and then the rest of the table as usual. Check if one of the answers in the linked post solves your problem. If not, tell us what is not working for you. – Phelype Oleinik Feb 3 '20 at 14:35
• Welcome to TeX.SE. Please tell us more about your formatting requirements. E.g., do you need the contents of cells to "wrap" automatically in case they exceed a certain width? – Mico Feb 3 '20 at 14:37
• @sigfest -- you have deleted the accepted check mark for the answer, though it was the first answer which met your requirements -- and with due courtesy mention to the original post -- so may I ask why the change – js bibra Feb 3 '20 at 16:03

Some suggestions and comments:

• The table shown in your screenshot is very "traditional", i.e., rather cramped, unattractive and uninviting. The overall impression is that of a prison cell window: Lots and lots of horizontal and vertical bars. Its "look" is shown in the first table below.

• Do give some thought to giving the table a more open "look". A very good way of doing so is to (a) omit all vertical lines and (b) use fewer but well-spaced horizontal lines. Do check out the result in the second table below.

• As a variation of the second approach, a tabular* environment could be used instead a tabular environment, to permit pre-specifying the overall width of the table. Usually, but not necessarily, the overall width is set as \textwidth, i.e., the width of the text block.

A final comment: None of these three approaches actually guarantees that the table will fit inside the text block. This problem is especially likely to occur if the table has lots of columns. If that's a problem you're encountering, you should post a new query, in which you lay out what you've tried so far.

\documentclass{article}
\usepackage{array,multirow}
\usepackage{booktabs} % for \toprule, \midrule, \cmidrule, and \bottomrule macros

\usepackage{newtxtext} % optional: load Times Roman clone text font

\begin{document}

\begin{table}
\centering

%% A. For the "traditional", i.e., cramped and rather unattractive "look":
\setlength\extrarowheight{2pt} % optional
\begin{tabular}{|l|*{8}{c|}}
\hline
\multirow{2}{*}{\textbf{Mapping Method}} &
\multicolumn{4}{c|}{\textbf{SVM (\%)}} &
\multicolumn{4}{c|}{\textbf{kNN (\%)}} \\
\cline{2-9}
& \textbf{AC} & \textbf{SP} & \textbf{SN} & \textbf{AUC}
& \textbf{AC} & \textbf{SP} & \textbf{SN} & \textbf{AUC} \\
\hline
\dots & & & & & & & & \\ \hline
\dots & & & & & & & & \\ \hline
\dots & & & & & & & & \\ \hline
\dots & & & & & & & & \\
\hline
\end{tabular}

\bigskip\bigskip
%% B. A much more open "look" (no vertical rules, few but well-spaced horizontal rules)
\setlength\extrarowheight{0pt} % reset to default value
\begin{tabular}{@{}l*{8}{c}@{}}
\toprule
\textbf{Mapping Method} &
\multicolumn{4}{c}{\textbf{SVM (\%)}} &
\multicolumn{4}{c@{}}{\textbf{kNN (\%)}} \\
\cmidrule(lr){2-5} \cmidrule(l){6-9}
& \textbf{AC} & \textbf{SP} & \textbf{SN} & \textbf{AUC}
& \textbf{AC} & \textbf{SP} & \textbf{SN} & \textbf{AUC} \\
\midrule
\dots & & & & & & & & \\
\dots & & & & & & & & \\
\dots & & & & & & & & \\
\dots & & & & & & & & \\
\bottomrule
\end{tabular}

\bigskip\bigskip
%% C. Same as "B" , but with overall width set to \textwidth
\setlength{\tabcolsep}{0pt}
\begin{tabular*}{\textwidth}{@{\extracolsep{\fill}} l *{8}{c} }
\toprule
\textbf{Mapping Method} &
\multicolumn{4}{c}{\textbf{SVM (\%)}} &
\multicolumn{4}{c}{\textbf{kNN (\%)}} \\
\cmidrule{2-5} \cmidrule{6-9}
& \textbf{AC} & \textbf{SP} & \textbf{SN} & \textbf{AUC}
& \textbf{AC} & \textbf{SP} & \textbf{SN} & \textbf{AUC} \\
\midrule
\dots & & & & & & & & \\
\dots & & & & & & & & \\
\dots & & & & & & & & \\ %\hline
\dots & & & & & & & & \\
\bottomrule
\end{tabular*}
\end{table}
\end{document}

• Thank you mate. This is also what i wanted too. Really appreciated. – sigfest Feb 3 '20 at 15:36

The following solution, proposed originally by @Mico at https://tex.stackexchange.com/a/192332/197451, should suit your purpose:

\documentclass{article}
\usepackage[margin=1in]{geometry}
\usepackage{multirow,tabularx}
\newcolumntype{Y}{>{\centering\arraybackslash}X}
\renewcommand{\arraystretch}{2}
\begin{document}

\emph{Original form: All columns are equally wide.}

\noindent
\begin{tabularx}{\textwidth}{|*{4}{Y|}}
\hline
\multirow{2}{*}{State of Health}
&\multicolumn{2}{c|}{Fasting Value}&After Eating\\
\cline{2-4}
&Minimum       &Maximum &2 hours after eating\\
\hline
Healthy      &70            &100     &Less than 140\\
\hline
Pre-Diabetes &101           &126     &140 to 200\\
\hline
Diabetes     &More than 126 &N/A     &More than 200\\
\hline
\end{tabularx}

\bigskip
\emph{Modified form: Columns 1 and 4 are 50\% wider than columns 2 and 3.}

\smallskip\noindent
\begin{tabularx}{\textwidth}{|
>{\hsize=1.2\hsize}Y|
>{\hsize=0.8\hsize}Y|
>{\hsize=0.8\hsize}Y|
>{\hsize=1.2\hsize}Y|}
\hline
\multirow{2}{*}{State of Health}
&\multicolumn{2}{c|}{Fasting Value}&After Eating\\
\cline{2-4}
&Minimum       &Maximum &2 hours after eating\\
\hline
Healthy      &70            &100     &Less than 140\\
\hline
Pre-Diabetes &101           &126     &140 to 200\\
\hline
Diabetes     &More than 126 &N/A     &More than 200\\
\hline
\end{tabularx}
\end{document}

• Yeah this is what i wanted. Thank you mate. Really appreciated. – sigfest Feb 3 '20 at 15:29
• @Mico -- agreed -- would you like me to delete the answer -- I try to follow all your solutions – js bibra Feb 3 '20 at 15:37
• No, please don't delete. Maybe change the opening sentence, though? – Mico Feb 3 '20 at 15:57
• @Mico -- please edit as per your choice – js bibra Feb 3 '20 at 16:00