[Tex/LaTex] How to create a complicated table in latex

multirowtables

I am trying to create a table in LateX that looks like the following:

enter image description here

Could anyone plz tell me what the corresponding LateX code would be? Thank you in advance.

Best Answer

I suggest you aim for a table with an open, easily-accessible look. To that effect, get rid of all vertical rules and most horizontal rules. (Whatever you do, try to avoid creating tables with random-looking widths for horizontal and/or vertical rules.) Use the macros of the booktabs package to draw the remaining few rules with good spacing.

There's a lot of math material in the table. One can specify the column type as >{$}c<{$} to get center-set columns whose contents are in math mode automatically; this'll save you a lot of typing of $ symbols.

People also usually do not like to have to crane their necks to read material that's been rotated by 90 degrees. In your case, the table works just as well (and maybe even better...) if you place the word "Subject" in the top line of the table's header.

To color in (or gray) various cells, use the \cellcolor{<color>} macro of the colortbl package. For available color names, consult the user guide of the xcolor package.

I'll leave it you to fill in the remaining 32 cells.

enter image description here

\documentclass{article}
\usepackage{booktabs,multirow,array}
\usepackage[table]{xcolor} % load both xcolor and colortbl
\begin{document}
\begin{table}
\centering
\begin{tabular}{@{} l*{5}{>{$}c<{$}} @{}}
\toprule
Subject & \multicolumn{5}{c@{}}{$N_{\textnormal{trials}}$}\\
\cmidrule(l){2-6}
& 20 & 60 & 100 & 140 & 180 \\
\midrule
\multirow{2}{*}{AD} & 50.5\pm 3.2 & 50.3\pm4.5 & 52.6\pm4.7 & 51.7\pm5.3 & 51.5\pm 8.4\\
& \cellcolor{lightgray} 74.8\pm4.9 & \\[1ex]
\multirow{2}{*}{AS} & 50.4\pm3.6 & & & \\ 
& 74.9\pm6.8 & & & & \\
\multirow{2}{*}{NR} & 50.3\pm2.7 & & & \\ 
& 75.2\pm6.5 & & & & \\
\multirow{2}{*}{RA} & 49.9\pm2.7& & &\\ 
& 74.8\pm6.6& & & &\\
\midrule
\multirow{2}{*}{Average} & 50.3\pm3.0& & &\\
 & 74.9\pm6.2& & & &\\
\bottomrule
\end{tabular}
\end{table}
\end{document}