1

enter image description here

I want to write table code for the table in attached image. I tried but unable to get this form.

    \begin{tabular}{|llllllll|}
\hline

A & \multicolumn{7}{|l}{B} \\

\hline

&\multicolumn{3}{|l|}{C} & \multicolumn{2}{l|}{D} & \multicolumn{2}{l}{E}\\

\hline

&\multicolumn{1}{|l|}{F}& \multicolumn{1}{l|}{G} & \multicolumn{1}{l|}{H} & \multicolumn{1}{l|}{I} & \multicolumn{1}{l|}{J} & \multicolumn{1}{l|}{K}& \multicolumn{1}{l}{L}\\

\hline
M &&&&&&&\\

\hline

\end{tabular}
5
  • There are many tools on line to generate your table. You can see this link: tex.stackexchange.com/questions/49414/…
    – Sebastiano
    Commented Apr 28, 2018 at 7:13
  • 4
    Please add a minimal working example (MWE) of what you tried so far.
    – CarLaTeX
    Commented Apr 28, 2018 at 7:14
  • \begin{tabular}{|llllllll|} \hline %\cline{3-3} A & \multicolumn{7}{|l}{B} \\ \hline &\multicolumn{3}{|l|}{C} & \multicolumn{2}{l|}{D} & \multicolumn{2}{l}{E}\\ \hline &\multicolumn{1}{|l|}{F}& \multicolumn{1}{l|}{G} & \multicolumn{1}{l|}{H} & \multicolumn{1}{l|}{I} & \multicolumn{1}{l|}{J} & \multicolumn{1}{l|}{K}& \multicolumn{1}{l}{L}\\ \hline M &&&&&&&\\ \hline \end{tabular} Commented Apr 28, 2018 at 10:13
  • Please add a minimal working example (MWE) of what you tried so far. currently only posted part where tabular is used, MWE should be compilable ((a.o. start with documentclass etc.)
    – albert
    Commented Apr 28, 2018 at 10:38
  • @SaqibQamar, your question only slightly differ from your previous in tex.stackexchange.com/questions/405393/… (actually your question above is duplicate to it). you should read some introductory text how to write tables (for example en.wikibooks.org/wiki/LaTeX/Tables) and learn how to managed this small differences in your tables and ask for help when you stuck in this. btw, so far you not accept any of received answer. did not anyone solve your problem?
    – Zarko
    Commented Apr 28, 2018 at 11:56

2 Answers 2

1

Here are some working assumptions I had to make:

  • The eight columns should all be equally wide
  • The table should span the full width of the text block
  • Material in the left-hand column should be left-aligned
  • Material in the header cells above columns 2 thru 8 should be centered
  • Material in the data cells in columns 2 thru 8 should be left-aligned
  • Automatic line-breaking should be enabled in all cells, including all header cells.

If these assumptions are correct, the following code should be of interest to you. Both solutions shown here are based on the tabularx package, and they both satisfy the criteria laid out above. The first solution uses a "traditional" layout, with lots of horizontal and vertical bars. The second solution, with goes for a more open "look", uses no vertical bars at all and uses fewer but well-spaced horizontal lines.

enter image description here

\documentclass{article}
\usepackage{tabularx,ragged2e,booktabs}
\newcolumntype{C}{>{\Centering\arraybackslash}X}
\newcolumntype{L}{>{\RaggedRight\arraybackslash}X}

\newcommand\mC[1]{\multicolumn{1}{C|}{#1}} % handy shortcut macro
\begin{document}

\setlength\extrarowheight{2pt}
\noindent
\begin{tabularx}{\textwidth}{|*{8}{L|}}
\hline
& \multicolumn{7}{c|}{B}\\
\cline{2-8}
A & \multicolumn{3}{c|}{C} & \multicolumn{2}{c|}{D} & \multicolumn{2}{c|}{E} \\
\cline{2-8}
& \mC{F} & \mC{G} & \mC{H} & \mC{I} & \mC{J} & \mC{K} & \mC{L} \\
\hline
M & & & & & & & \\
\hline
N & & & & & & & \\
\hline
\end{tabularx}

\renewcommand\mC[1]{\multicolumn{1}{C}{#1}}
\setlength\extrarowheight{0pt}
\bigskip\noindent
\begin{tabularx}{\textwidth}{*{8}{L}}
\toprule
& \multicolumn{7}{c}{B}\\
\cmidrule(l){2-8}
A & \multicolumn{3}{c}{C} & \multicolumn{2}{c}{D} & \multicolumn{2}{c}{E} \\
\cmidrule(lr){2-4} \cmidrule(lr){5-6} \cmidrule(l){7-8}
& \mC{F} & \mC{G} & \mC{H} & \mC{I} & \mC{J} & \mC{K} & \mC{L} \\
\midrule
M & & & & & & & \\
N & & & & & & & \\
\bottomrule
\end{tabularx}
\end{document}
0

In the following MWE, I have removed superfluous \multicolumn{1} commands, replaced two \hlines by \cline, added | where needed and replaced l column types by c column types (horizontally centered).

\documentclass{article}
\begin{document}

\begin{tabular}{|c|c|c|c|c|c|c|c|}
\hline
 & \multicolumn{7}{|c|}{B} \\
\cline{2-8}
A & \multicolumn{3}{|c|}{C} & \multicolumn{2}{c|}{D} & \multicolumn{2}{c|}{E}\\
\cline{2-8}
& F & G & H & I & J & K & L\\
\hline
M &&&&&&&\\
\hline
\end{tabular}

\end{document} 

enter image description here

Depending on the real contents of your table, you might consider removing the vertical lines completely and replace \hline by the rules from the booktabs package.

1
  • 1
    I'd add \renewcommand{\arraystretch}{1.2} from array package.
    – CarLaTeX
    Commented Apr 28, 2018 at 10:56

You must log in to answer this question.

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