[Tex/LaTex] How to create complicated tables (multiple nested columns and rows)

tables

I have an image of a table that I want to replicate but I can't figure out how to do the multiple rows part (see left side of column) and the multiple columns part (see right side).

Is there a general way to do this? How do you go about creating such tables? The numbers are irrelevant, I'm looking for a piece of code that I can easily extend as necessary (add more rows/colums).

Complicated table

Edit:

Thanks to @leandriis, the following works well:

\begin{tabular}{c|c|cccccc}
%\toprule
Metric & Dataset & 
%\multicolumn{6}{c}{SGAN (Ours)}\\ \cmidrule{3-8} & &
\makecell[b]{20V-20 \\ (pretrained)} & \makecell[b]{20VP-20 \\ (pretrained)} & \makecell[b]{20VP-20 \\ (retrained)} & \makecell[b]{Mean \\ Pooling} & \makecell[b]{Random \\ Pooling} & \makecell[b]{Gumble \\ Pooling}\\
\midrule
 & ETH & 3 & 3 & 3 \\
 & ETH & 3 & 3 & 3 \\
 ADE & ETH & 3 & 3 & 3 \\
 & ETH & 3  & 3 & 3\\
  & ETH & 3 & 3 & 3 \\ 
  AVG & & 3 & 3 & 3 \\
  \midrule\midrule
 & ETH & 3 & 3 & 3 \\
 & ETH & 3 & 3 & 3 \\
 ADE  & ETH & 3 & 3 & 3 \\
 & ETH & 3  & 3 & 3\\
  & ETH & 3 & 3 & 3 \\ 
  AVG & & 3 & 3 & 3 \\
\bottomrule\bottomrule
\end{tabular}

Resulting table

Best Answer

Here is a short code, that might serve as a place to start from. I have included some \multicolumn an \multirow commands in order to get the alignment that was mentioned in the question.

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

\begin{tabular}{c|c|c|c|c}
\multirow{2}{*}{\textbf{Metric}} & \multirow{2}{*}{\textbf{Dataset}} & 
\multicolumn{3}{c}{\textbf{SGAN (Ours)}}\\
& & 1V-1 & 1V-20 & 20V-20\\
\hline \hline
 & \textbf{ETH} & 3 & 3 & 3 \\
 & \textbf{ETH} & 3 & 3 & 3 \\
ADE  & \textbf{ETH} & 3 & 3 & 3 \\
 & \textbf{ETH} & 3  & 3 & 3\\
  & \textbf{ETH} & 3 & 3 & 3 \\
\hline
\textbf{AVG} & & & & \\
\hline\hline
 & \textbf{ETH} & 3 & 3 & 3 \\
 & \textbf{ETH} & 3 & 3 & 3 \\
ADE  & \textbf{ETH} & 3 & 3 & 3 \\
 & \textbf{ETH} & 3  & 3 & 3\\
  & \textbf{ETH} & 3 & 3 & 3 \\
\hline
\textbf{AVG} & & & & 
\end{tabular}

\end{document}

Here is also a suggestion on how to use the booktabs package in order to create a table that has no vertical and just a few horizontal lines with some additional white space around them. I'd also suggest to not use bold for the column headers and the contents of the first/second column:

\documentclass{article}
\usepackage{booktabs}

\begin{document}

\begin{tabular}{ccccc}
\toprule
Metric & Dataset & 
\multicolumn{3}{c}{SGAN (Ours)}\\ \cmidrule{3-5}
& & 1V-1 & 1V-20 & 20V-20\\
\midrule
ADE & ETH & 3 & 3 & 3 \\
 & ETH & 3 & 3 & 3 \\
  & ETH & 3 & 3 & 3 \\
 & ETH & 3  & 3 & 3\\
  & ETH & 3 & 3 & 3 \\ 
  AVG & & 3 & 3 & 3 \\
  \midrule
ADE & ETH & 3 & 3 & 3 \\
 & ETH & 3 & 3 & 3 \\
  & ETH & 3 & 3 & 3 \\
 & ETH & 3  & 3 & 3\\
  & ETH & 3 & 3 & 3 \\ 
  AVG & & 3 & 3 & 3 \\
\bottomrule
\end{tabular}

\end{document}

Here is a comparison of both tables side by side:

enter image description here

For an improved alignment of the numbers in column 3-9 I'd suggest tue usage of the siunitx package.

Related Question