How to make a table like this? I have tried many ways to do it but all are failed. I am so confused.
Thank you so much for any reply.
1 Answer
The following is how I'd recreate your table (but with top-aligned contents for the columns 1 and 2).
I use booktabs
for the rules, siunitx
for the S
-type columns which nicely align numbers, amsmath
is just loaded for \boldsymbol
to get a bold >
, and I defined a macro for the table headers myself, to format all of them the same way (you could've used makecell
and its \thead
here as well).
\documentclass[border=3.14]{standalone}
\usepackage{booktabs}
\usepackage{siunitx}
\usepackage[]{amsmath}
\newcommand\myhead[1]{\myheadset\begin{tabular}[c]{@{}c@{}}#1\end{tabular}}
\newcommand\myheadset{\bfseries}
\begin{document}
\begin{tabular}{cccS[table-format=3]*{4}{S[table-format=1]}}
\toprule
\myhead{Type} & & & {\myhead{DF}} & {\myhead{Sum of\\Squares}}
& {\myhead{Mean\\Squares}} & {\myhead{F Value}}
& {\myhead{Prob$\boldsymbol{>}$F}} \\
\midrule
\myhead{City} & \myhead{Overall} & \myhead{Model} & 9 & 1 & 1 & 1 & 1 \\
\myhead{Group} & \myhead{ANOVA} & \myhead{Error} & 180 & 1 & 1 & & \\
&&\myhead{Total} & 189 & 1 & & & \\
\cmidrule{2-8}
&\myhead{Levene's Test} & \myhead{Model} & 9 & 1 & 1 & 1 & 1 \\
&&\myhead{Error} & 180 & 1 & 1 & & \\
\midrule[\heavyrulewidth]
\myhead{Year} & \myhead{Overall} & \myhead{Model} & 18 & 1 & 1 & 1 & 1 \\
\myhead{Group} & \myhead{ANOVA} & \myhead{Error} & 171 & 7 & 1 & & \\
&&\myhead{Total} & 189 & 1 & & & \\
\cmidrule{2-8}
&\myhead{Levene's Test} & \myhead{Model} & 18 & 1 & 1 & 1 & 1 \\
&&\myhead{Error} & 171 & 1 & 1 & & \\
\bottomrule
\end{tabular}
\end{document}
\multicolumn
and\multirow
\usepackage{booktabs}
the first rule is\toprule
, the second\midrule
, then\cmidrule{2-8}
,\midrule
,\cmidrule{2-8}
and\bottomrule
.\multirow
is an option, most of the time it only makes things more complicated. In your header, you can use\makecell
(from the eponymous package) for those which need two rows. The things from columns 1 and 2 I'd just top align.