表格列未正确分隔

表格列未正确分隔

以下代码生成一个表格。右半部分(青蛙)的列分布与左半部分(鸟类)不同。如何使其正常工作? 在此处输入图片描述

\documentclass{article}
\usepackage{multirow}   
\begin{document}
\begin{table}
\centering
\begin{tabular}{c|c| c|c| c|c| c|c |c}
\multirow{2}{*}{AAA} & \multicolumn{4}{c|}{birds} & \multicolumn{4}{c}{frogs} \\ \cline{2-9}
& \multicolumn{2}{c|}{w/o huge hat} & \multicolumn{2}{c|}{w/ huge hat} & \multicolumn{2}{c|}{w/o huge hat} & \multicolumn{2}{c}{w/ huge hat} \\
\hline
$\frac{1}{3}$ & 2.75 & 3.6 & 2.75 & 3.68 & 5 & 5 & 5 & 5 \\ \hline
1 & 8.3 & 10 & 8.2 & 10 & 15 & 15 & 15 & 15 \\ \hline
3 & 24.25 & 28 & 24.25 & 28.5 & 44 & 48 & 45 & 45 \\ \hline\hline
$\frac{p}{q}$ & $\frac{31}{97}$ & $\frac{53}{157}$ & $\frac{31}{97}$ & $\frac{53}{157}$ & $\frac{31}{97}$ & $\frac{53}{157}$ & $\frac{31}{97}$ & $\frac{53}{157}$ \\ 
\end{tabular}
\end{table}
\end{document}

答案1

如同@Zarko 的回答但省略了所有垂直线,并使用了更少但间距适当的水平线,以创造更加开放的“外观”。

在此处输入图片描述

\documentclass{article}
\usepackage{tabularx,booktabs,ragged2e}  
\newcolumntype{C}{>{\Centering}X} 

\begin{document}
\begin{table}
\begin{tabularx}{\textwidth}{@{} c *{8}{C} @{}}
AAA & \multicolumn{4}{c}{birds} & \multicolumn{4}{c@{}}{frogs} \\ 
\cmidrule(lr){2-5} \cmidrule(l){6-9}
& \multicolumn{2}{c}{w/o huge hat} & \multicolumn{2}{c}{w/ huge hat} 
& \multicolumn{2}{c}{w/o huge hat} & \multicolumn{2}{c@{}}{w/ huge hat} \\
\cmidrule(lr){2-3} \cmidrule(lr){4-5} \cmidrule(lr){6-7} \cmidrule(l){8-9} 
$1/3$ & 2.75 & 3.6 & 2.75 & 3.68 & 5 & 5 & 5 & 5 \\
1 & 8.3 & 10 & 8.2 & 10 & 15 & 15 & 15 & 15 \\ 
3 & 24.25 & 28 & 24.25 & 28.5 & 44 & 48 & 45 & 45 \\ 
\midrule
$p/q$ & $\frac{31}{97}$ & $\frac{53}{157}$ & $\frac{31}{97}$ & $\frac{53}{157}$ 
   & $\frac{31}{97}$ & $\frac{53}{157}$ & $\frac{31}{97}$ & $\frac{53}{157}$ \\ 
\end{tabularx}
\end{table}
\end{document}

答案2

多列单元格的宽度w/o huge hat大于跨列宽度的总和。要使列的宽度相等,您需要定义它们的宽度(例如p{<width>}),或者更简单地使用tabularx所有列的宽度相等:

\documentclass{article}
\usepackage{multirow, tabularx}
\newcolumntype{C}{>{\centering\arraybackslash}X}

\begin{document}
\begin{table}
\centering
\begin{tabularx}{\linewidth}{C|C| C|C| C|C| C|C |C}
\multirow{2}{*}{AAA} & \multicolumn{4}{c|}{birds} & \multicolumn{4}{c}{frogs} \\ \cline{2-9}
& \multicolumn{2}{c|}{w/o huge hat} & \multicolumn{2}{c|}{w/ huge hat} & \multicolumn{2}{c|}{w/o huge hat} & \multicolumn{2}{c}{w/ huge hat} \\
\hline
$\frac{1}{3}$ & 2.75 & 3.6 & 2.75 & 3.68 & 5 & 5 & 5 & 5 \\ \hline
1 & 8.3 & 10 & 8.2 & 10 & 15 & 15 & 15 & 15 \\ \hline
3 & 24.25 & 28 & 24.25 & 28.5 & 44 & 48 & 45 & 45 \\ \hline\hline
$\frac{p}{q}$ & $\frac{31}{97}$ & $\frac{53}{157}$ & $\frac{31}{97}$ & $\frac{53}{157}$ & $\frac{31}{97}$ & $\frac{53}{157}$ & $\frac{31}{97}$ & $\frac{53}{157}$ \\
\end{tabularx}
\end{table}
\end{document}

在此处输入图片描述

相关内容