答案1
使用以下方式您的表格会显得更加专业booktabs
。
我用过\makecell
多行来实现更好的垂直对齐。
下次询问时,请添加您尝试过的最简单的例子。
编辑:我还添加了 TeXnician 的更优雅的解决方案,其中前两列交换,以及另一个交换行和列的解决方案
\documentclass{article}
\usepackage{array}
\renewcommand{\arraystretch}{1.1}
\newcolumntype{C}{>{\centering\arraybackslash}p{1em}}
\usepackage{booktabs}
\usepackage{multirow}
\usepackage{makecell}
\usepackage{caption}
\begin{document}
\begin{table}[htb]
\centering
\caption{My professional table\label{tab:my_label}}
\begin{tabular}{*{7}{c}}
\toprule
\multirow{2}{*}{Observation} & \multirow{2}{*}{Class} & \multicolumn{5}{c}{Binary attributes} \\
\cmidrule(lr){3-7}
& & $b_1$ & $b_2$ & $b_3$ & $b_4$ & $b_5$\\
\midrule
1 & \multirow{4}{*}{\makecell{(Positive)\\$\Omega^+$}} & 1 & 1 & 1 & 0 & 0 \\
2 & & 1 & 1 & 1 & 1 & 1 \\
3 & & 1 & 0 & 1 & 1 & 0 \\
4 & & 1 & 1 & 1 & 1 & 0 \\
\midrule
5 & \multirow{4}{*}{\makecell{(Negative)\\$\Omega^-$}} & 1 & 0 & 1 & 0 & 0 \\
6 & & 0 & 0 & 0 & 0 & 0 \\
7 & & 0 & 0 & 1 & 0 & 0 \\
8 & & 1 & 0 & 0 & 0 & 0 \\
\bottomrule
\end{tabular}
\end{table}
\begin{table}[htb]
\centering
\caption{A professional table (\TeX nician's suggestion)\label{tab:tex_label}}
\begin{tabular}{l*{6}{c}}
\toprule
Class & Observation & \multicolumn{5}{c}{Binary attributes} \\
\cmidrule(lr){3-7}
& & $b_1$ & $b_2$ & $b_3$ & $b_4$ & $b_5$\\
\midrule
(Positive) $\Omega^+$ & 1 & 1 & 1 & 1 & 0 & 0 \\
& 2 & 1 & 1 & 1 & 1 & 1 \\
& 3 & 1 & 0 & 1 & 1 & 0 \\
& 4 & 1 & 1 & 1 & 1 & 0 \\
\midrule
(Negative) $\Omega^-$ & 5 & 1 & 0 & 1 & 0 & 0 \\
& 6 & 0 & 0 & 0 & 0 & 0 \\
& 7 & 0 & 0 & 1 & 0 & 0 \\
& 8 & 1 & 0 & 0 & 0 & 0 \\
\bottomrule
\end{tabular}
\end{table}
\begin{table}[htb]
\centering
\caption{Another kind of professional table\label{tab:other_label}}
\begin{tabular}{c*{8}{C}}
\toprule
& \multicolumn{8}{c}{Class}\\
& \multicolumn{4}{c}{(Positive) $\Omega^+$} & \multicolumn{4}{c}{(Negative) $\Omega^-$}\\
\cmidrule(lr){2-5}\cmidrule(lr){6-9}
\multirow{2}{*}{\makecell{Binary\\ attributes}} & \multicolumn{8}{c}{Observation}\\
& 1 & 2 & 3 & 4 & 5 & 6 & 7 & 8 \\
\cmidrule(lr){1-1}\cmidrule(lr){2-5}\cmidrule(lr){6-9}
$b_1$ & 1 & 1 & 1 & 1 & 1 & 0 & 0 & 1 \\
$b_2$ & 1 & 1 & 0 & 1 & 0 & 0 & 0 & 0 \\
$b_3$ & 1 & 1 & 1 & 1 & 1 & 0 & 1 & 0 \\
$b_4$ & 0 & 1 & 1 & 1 & 0 & 0 & 0 & 0 \\
$b_5$ & 0 & 1 & 0 & 0 & 0 & 0 & 0 & 0 \\
\bottomrule
\end{tabular}
\end{table}
\end{document}
答案2
给你一个开始。我正在使用这个答案。你必须纠正二进制数,我只是把它放到了1
各处。
\documentclass{article}
\usepackage{xcolor}
\usepackage{array}
\usepackage{colortbl}
\usepackage{booktabs}
\usepackage{multirow}
\begin{document}
\setlength{\aboverulesep}{-0.45pt} \setlength{\belowrulesep}{-0.45pt}
\begin{tabular}{*{7}{|c}|}
\hline
\rowcolor{gray!50} & & \multicolumn{5}{c|}{Binary attributes} \\[2pt]
\cmidrule[0.8pt]{3-7}
\rowcolor{gray!50}
\multirow{-2}{*}{ Observation} &
\multirow{-2}{*}{Class}& $b_1$ & $b_2$ & $b_3$ & $b_4$ & $b_5$\\
\hline
1 & & 1 & 1 & 1 & 1 & 1 \\
2 & (Positive) & 1 & 1 & 1 & 1 & 1 \\
3 &\multirow{2}{*}{$\Omega^*$} & 1 & 1 & 1 & 1 & 1 \\
4 & & 1 & 1 & 1 & 1 & 1 \\[1pt]
\midrule
\vphantom{$1^|$}5 & & 1 & 1 & 1 & 1 & 1 \\
6 & (Negative) & 1 & 1 & 1 & 1 & 1 \\
7 &\multirow{2}{*}{$\Omega^-$} & 1 & 1 & 1 & 1 & 1 \\
8 & & 1 & 1 & 1 & 1 & 1 \\
\hline
\end{tabular}
\end{document}