# Design a complex structure table in latex

I am new in latex. Thus, I can design basic table, not this complex one given below(this one designed in MS Word):

I think you are looking for \multicolumn and \multirow:

\documentclass{article}
\usepackage[margin=1cm]{geometry}
\usepackage{array}
\usepackage{multirow}
\newcolumntype{C}{>{\centering\let\newline\\\arraybackslash\hspace{0pt}}m{2.3cm}}
% https://tex.stackexchange.com/a/12712/156344
\begin{document}
\setcounter{table}{11}
\begin{table}
\centering
\caption{Some caption}
\begin{tabular}{|C|C|C|C|C|C|}
\hline
\multicolumn{3}{|c|}{Long long long long long long long long text} & \multicolumn{3}{c|}{Long long long long long long long long text}\\
\hline
Text & Primary Code & Text & Text & Text & Text\\
\hline
Text & Text & \multirow[t]{2}{*}{Some text} & Text & Text & \multirow[t]{2}{*}{Some text}\\ \cline{1-2} \cline{4-5}
Text & Text & & Text & Text & \\
\hline
\end{tabular}
\end{table}
\end{document}

The additional horizontal rules will mess up your table, so I removed it, and please don't use it.

And here is the recommended version, with all vertical lines removed and some changes in the thickness of horizontal lines (with the help of booktabs):

\documentclass{article}
\usepackage[margin=1cm]{geometry}
\usepackage{array}
\usepackage{multirow}
\usepackage{booktabs}
\newcolumntype{C}{>{\centering\let\newline\\\arraybackslash\hspace{0pt}}m{2.3cm}}
\begin{document}
\setcounter{table}{11}
\begin{table}
\centering
\caption{Some caption}
\begin{tabular}{CCCCCC}
\toprule
\multicolumn{3}{c}{Long long long long long long long long text} & \multicolumn{3}{c}{Long long long long long long long long text}\\
\midrule
Text & Primary Code & Text & Text & Text & Text\\
%\midrule
\cmidrule(r){1-3} \cmidrule(l){4-6} % For better column separation, thanks to Mico!
Text & Text & \multirow[t]{2}{*}{Some text} & Text & Text & \multirow[t]{2}{*}{Some text}\\
Text & Text & & Text & Text & \\
\bottomrule
\end{tabular}
\end{table}
\end{document}

• +1. Do consider replacing the first \midrule with \cmidrule(r){1-3} \cmidrule(l){4-6}. – Mico Mar 26 at 5:27
• @Mico Oh, thanks! I did not think of that. Btw, I think we should replace the second \midrule instead of the first. – JouleV Mar 26 at 5:28
• I think it's preferable to provide more visual structure to the header rows. Otherwise, it's not obvious whether "Some text" pertains just to "Primary Code" or to all three subheaders. – Mico Mar 26 at 5:38
• @Mico Thanks for the feedback. Added :) – JouleV Mar 26 at 5:42
• @JouleV Thanks for the help. I just tried your design with my data, it works fine. However, the table size breaks the page margin. How to limit the table within page margin. Please see the image here: imgur.com/ggav0Re – Nahid Hossain Shihab Mar 26 at 5:47

I suggest you employ a tabularx environment, overall width set to \textwidth, with 6 equal-width columns. I also suggest you omit all vertical lines and employ fewer, but well-spaced horizontal lines (using the macros of the booktabs package), to give the table a more open "look".

\documentclass{article} % select a suitable document class
\usepackage[a4paper,margin=2.5cm]{geometry} % set suitable page parameters
\usepackage[skip=0.333\baselineskip]{caption} % optional
\usepackage{tabularx,booktabs,ragged2e,amsmath}
\newcolumntype{C}{>{\Centering\arraybackslash}X}
\DeclareMathOperator{\ED}{ED}
\newcommand\ris{\mathrm{ris}}
\newcommand\rs{\mathrm{rs}}

\begin{document}
\begin{table}
\setlength\tabcolsep{3pt} % default: 6pt
\caption{Example comparison of \dots\ between previous and our approaches}

\begin{tabularx}{\textwidth}{@{} *{6}{C} @{}}
\toprule
\multicolumn{3}{@{}c}{\dots' coded ri' (Previous Approach)} &
\multicolumn{3}{c@{}}{\dots' coded r' (Our Approach)} \\
\cmidrule(r){1-3} \cmidrule(l){4-6}
Word & Primary Word & Edit Distance & Word & Primary Word & Edit Distance \\
\midrule
\dots\ (correct)   & Ris & $\ED(\ris\mid \rs)=1$ & & & \\ \addlinespace
\dots\ (incorrect) & Rs  &                       & & & \\
\bottomrule
\end{tabularx}
\end{table}
\end{document}