我想要一個tabular
具有完全合理的列的環境。我對如何實現這一點的最佳猜測是使用一個tabularx
環境(以便表格知道有多寬),然後將\hilll
(對於字母的適當重複l
)放在所有相鄰列之間。然而,這沒有用。請參閱下面的 MWE。
\documentclass{article}
\usepackage{tabularx}
\begin{document}
Text before. Text before. Text before. Text before. Text before. Text before. Text before.
\begin{tabularx}{\textwidth}{l@{\hfill}c@{\hfill}r}
On the LEFT & In the middle & On the RIGHT
\end{tabularx}
Text between. Text between. Text between. Text between. Text between. Text between. Text between.
\def\magicNumber{50pt}
\begin{tabularx}{\textwidth}{lcr}
On the LEFT & \hspace*{\magicNumber} In the middle \hspace*{\magicNumber} & On the RIGHT
\end{tabularx}
Text after. Text after. Text after. Text after. Text after. Text after. Text after. Text after.
\end{document}
第一個tabularx
環境是我失敗的嘗試。第二個tabularx
環境的排版(大約)正確,但是是使用幻數的駭客攻擊。
問題:
如何正確使用無限黏合(如)來指定列\hfill
之間的空間?tabularx
更一般地說,如何獲得一個tabular
具有完全合理的列的環境?
答案1
tabularx
僅當您使用X
-column 時才有效。您感興趣的可能是設置\extracolsep{\fill}
,如中所建議的表格中的列和行填充:
\documentclass{article}
\begin{document}
Text before. Text before. Text before. Text before. Text before. Text before. Text before.
\noindent
\begin{tabular*}{\linewidth}{@{}@{\extracolsep{\fill}}lcr@{}}
On the LEFT & In the MIDDLE & On the RIGHT
\end{tabular*}
Text after. Text after. Text after. Text after. Text after. Text after. Text after. Text after.
\noindent
\begin{tabular*}{\linewidth}{@{}@{\extracolsep{\fill}}lcr@{}}
On the LEFT & In the very MIDDLE & On the RIGHT
\end{tabular*}
\end{document}
請注意,以上並不代表「完全合理」的欄位。為此你可以使用
\documentclass{article}
\usepackage{tabularx}
\begin{document}
Text before. Text before. Text before. Text before. Text before. Text before. Text before.
\noindent
\begin{tabularx}{\linewidth}{@{}XXX@{}}
On the LEFT & In the MIDDLE & On the RIGHT
\end{tabularx}
Text after. Text after. Text after. Text after. Text after. Text after. Text after. Text after.
\end{document}
如果需要,您可以使用以下命令修改列的對齊方式array
包裹。