I have read about multicolumn in latex but I couldn't figure this out. How can I draw this table with assumptions that the width of A and B are evenly distributed, likewise for F,G,H,I,J and K.
3 Answers
Here are two possible solutions. The first solution generates minimum-width columns; observe that they don't have to have the same widths. The second solution uses fixed widths for all columns; I'm assuming that columns 3 thru 8 should all have the same width.
\documentclass{article}
\usepackage{array} % for '\newcolumntype' and '\extrarowheight' macros
\newcolumntype{C}[1]{>{\centering\arraybackslash}p{#1}} % centered version of 'p' column type
\renewcommand{\familydefault}{\sfdefault} % optional
\begin{document}
\begin{center}
\setlength{\extrarowheight}{3pt} % for a more open "look"
%% first solution: 'c' column type for all 8 columns
\begin{tabular}{|*{8}{c|}}
\hline
& & \multicolumn{6}{c|}{C} \\
\cline{3-8}
A & B & \multicolumn{3}{c|}{D} & \multicolumn{3}{c|}{E}\\
\cline{3-8}
& & F & G & H & I & J & K \\ \hline
& & & & & & & \\ \hline
& & & & & & & \\ \hline
& & & & & & & \\ \hline
\end{tabular}
\bigskip
%% second solution: use 'C' column type, with various widths
\begin{tabular}{|C{8mm}|C{6mm}|*{6}{C{4mm}|}} % set suitable column widths
\hline
& & \multicolumn{6}{c|}{C} \\
\cline{3-8}
A & B & \multicolumn{3}{c|}{D} & \multicolumn{3}{c|}{E}\\
\cline{3-8}
& & F & G & H & I & J & K \\ \hline
& & & & & & & \\ \hline
& & & & & & & \\ \hline
& & & & & & & \\ \hline
\end{tabular}
\end{center}
\end{document}
You can do that with {NiceTabular}
of nicematrix
.
In this environment, you create 'blocks' with a command \Block
and then, you only have to use the key hvlines
to draw all the rules excepted rules.
\documentclass{article}
\usepackage{nicematrix}
\begin{document}
\setlength{\extrarowheight}{3pt}
\begin{NiceTabular}{*{8}{c}}[columns-width=6mm,hvlines]
\Block{3-1}{A} & \Block{3-1}{B} & \Block{1-6}{C} \\
& & \Block{1-3}{D} & & & \Block{1-3}{E} \\
& & F & G & H & I & J & K \\
\\
\\
\\
\end{NiceTabular}
\end{document}
You need several compilations because nicematrix
uses PGF/Tikz.
In this particular case, I would use a tool to create latex tables such as https://www.tablesgenerator.com/ and manually enter in the data.
For example
% Please add the following required packages to your document preamble:
% \usepackage{multirow}
\begin{table}[]
\begin{tabular}{lllllllllll}
\multicolumn{2}{l}{\multirow{6}{*}{A}} & \multirow{6}{*}{B} & \multicolumn{8}{l}{\multirow{2}{*}{C}} \\
\multicolumn{2}{l}{} & & \multicolumn{8}{l}{} \\
\multicolumn{2}{l}{} & & \multicolumn{4}{l}{\multirow{2}{*}{D}} & \multicolumn{4}{l}{\multirow{2}{*}{E}} \\
\multicolumn{2}{l}{} & & \multicolumn{4}{l}{} & \multicolumn{4}{l}{} \\
\multicolumn{2}{l}{} & & \multicolumn{2}{l}{\multirow{2}{*}{F}} & \multirow{2}{*}{G} & \multicolumn{2}{l}{\multirow{2}{*}{H}} & \multicolumn{3}{l}{\multirow{2}{*}{K}} \\
\multicolumn{2}{l}{} & & \multicolumn{2}{l}{} & & \multicolumn{2}{l}{} & \multicolumn{3}{l}{} \\
& & & & & & & & & & \\
& & & & & & & & & &
\end{tabular}
\end{table}
-
1Did you try to actually generate a table based on this code? The result doesn't resemble the OP's table, I'm afraid.– MicoAug 22, 2018 at 20:15
-
Hmm, oh well, maybe I should check next time? and have included borders Aug 22, 2018 at 21:43
-
The absent vertical and horizontal lines are a minor issue. Do look into the issue of where the capital letters "I" and "J" are supposed to go.– MicoAug 22, 2018 at 21:53
\smash\parbox
to overlay the empty rows)