![表格中单元格分布均匀](https://linux22.com/image/409037/%E8%A1%A8%E6%A0%BC%E4%B8%AD%E5%8D%95%E5%85%83%E6%A0%BC%E5%88%86%E5%B8%83%E5%9D%87%E5%8C%80.png)
我需要显示包含值的 n 列表格(假设为 5 个)。该表应完全填满可用空间。但我需要列与列之间有均匀的间距,这些间距将根据可用空间自动调整。
如何实现这种均匀的间距?我试过了,\hfill
但没有成功。
[![图中的问题][1]][1]
\documentclass{article}
\usepackage{tabularx}
\begin{document}
\begin{table}[htbp]
\centering
\begin{tabularx}{\textwidth}{|llllll|}
\hline
this& negligible& countless& sizeable& any\\
\hline
reassembling& impoverished& political& backlash& devastating \\
\hline
\end{tabularx}
Table 1
\end{table}
\begin{table}[htbp]
\centering
\begin{tabularx}{\textwidth}{|XXXXXX|}
\hline
this& negligible& countless& sizeable& any\\
\hline
reassembling& impoverished& political& backlash& devastating \\
\hline
\end{tabularx}
Table 2
\end{table}
\end{document}```
[1]: https://i.stack.imgur.com/yST9G.png
答案1
也许这就是你要找的东西?命令
\noindent\begin{tabular*}{\textwidth}
确保表格填充边距之间的可用空间。\noindent
如果您没有将表格放置在表格环境中(或将其居中),则有必要这样做。
{@{\extracolsep{\fill}}*{5}{c}}
设置五个普通(一行)居中列,其宽度将根据单元格内容进行调整。您可以使用l
或r
代替。
宣言
@{\extracolsep{\fill}}
和...一起
\setlength{\tabcolsep}{0pt}
确保所有列设置为其自然宽度后剩余的空间将均匀分布为列之间的空间。请参阅第二个示例中的最后三行以清楚地看到效果。
居中列
\documentclass{article}
\usepackage{array, booktabs}
\setlength{\extrarowheight}{1pt}
\setlength{\tabcolsep}{0pt}
\renewcommand*{\arraystretch}{1.1}
\begin{document}
\noindent\begin{tabular*}{\textwidth}{@{\extracolsep{\fill}}*{5}{c}}
\hline
unqualified &member & is &unavoidable &sometimes\\\midrule
sad & situation & but & my & boss \\
which & predominate & in & Asia & although \\
\bottomrule
\end{tabular*}
\end{document}
左对齐列
\noindent\begin{tabular*}{\textwidth}{@{\extracolsep{\fill}}*{5}{l}}
\hline
unqualified & member & is &unavoidable &sometimes\\\midrule
sad & situation & but & my & boss \\
which & dominate & in & Asia & although \\
1234567890 & 1234567890 & 1234567890 & 1234567890 & 1234567890\\
1234567890 & 1234567890 & 1234567890 & 1234567890 & 1234567890\\
1234567890 & 1234567890 & 1234567890 & 1234567890 & 1234567890\\
\bottomrule
\end{tabular*}