![如何设置表格与合并单元格自动对齐的列宽?](https://linux22.com/image/391260/%E5%A6%82%E4%BD%95%E8%AE%BE%E7%BD%AE%E8%A1%A8%E6%A0%BC%E4%B8%8E%E5%90%88%E5%B9%B6%E5%8D%95%E5%85%83%E6%A0%BC%E8%87%AA%E5%8A%A8%E5%AF%B9%E9%BD%90%E7%9A%84%E5%88%97%E5%AE%BD%EF%BC%9F.png)
我想要做的是制作一个如下所示格式的表格。目前,列的宽度不同,表格对于页面来说太宽了。它看起来如下:
我想做的是
1)将表格设置为与文本一样宽,以便它占据边距内的最大空间
2)设置包含结果的第2、3、4列宽度相同。
\begin{table}[H] \centering \caption{X} \label{X}
\begin{tabular}{cccc}
\textbf{References} & \textbf{Results 1} & \textbf{Results 2} & \textbf{Results 3} \\\hline\hline
Author (Year)
&
Answer Answer
&
Answer Answer Answer Answer
&
\begin{tabular}{c}
Answer Answer Answer Answer Answer Answer \\
Answer Answer Answer \\
\end{tabular}
\\\hline
Author (Year) &
\begin{tabular}{c}
Answer \\
Answer \\
\end{tabular}
&
Answer Answer
&
\begin{tabular}{c}
Answer Answer Answer \\
Answer Answer Answer \\
\end{tabular}
\\\hline
Author (Year) &
\begin{tabular}{c}
Answer \\
Answer \\
Answer \\
\end{tabular}
&
\multicolumn{2}{c}{Answer Answer Answer Answer Answer Answer Answer Answer }
\\\hline
\end{tabular}
\end{table}
答案1
无需tabularx
嵌套表格:
\documentclass{article}
\usepackage{geometry}
\usepackage{booktabs, tabularx}
\usepackage[skip=1ex]{caption}
\begin{document}
\begin{table}[htb]
\caption{X}
\label{X}
\begin{tabularx}{\linewidth}{@{} l *{3}{>{\centering\arraybackslash}X} @{}}
\toprule
\textbf{References} & \textbf{Results 1} & \textbf{Results 2} & \textbf{Results 3} \\
\midrule
Author (Year)
& Answer Answer
& Answer Answer Answer Answer
& Answer Answer Answer Answer Answer Answer
Answer Answer Answer \\
\midrule
Author (Year)
& Answer
Answer
& Answer Answer
& Answer Answer Answer
Answer Answer Answer \\
\midrule
Author (Year)
& Answer
Answer
Answer
& \multicolumn{2}{>{\hsize=\dimexpr2\hsize+2\tabcolsep\relax
\centering\arraybackslash}X}{%
Answer Answer Answer Answer Answer Answer Answer Answer } \\
\bottomrule
\end{tabularx}
\end{table}
\end{document}
我宁愿使用左对齐,而不是水平居中的单元格文本,即而不是>{\centering\arraybackslash}X
使用>{\raggedright\arraybackslash}X