答案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}