I have a table that is narrower than a page, and would like to pad each column by an equal amount to fill the available width.
(The aim is to create more space around the narrower columns; as I am generating tables programmatically, adding a fixed amount of space risks unintentionally making the table wider than the available space.)
There are some solutions proposed online that set equal column widths; this will not work for me, as one column is wider than the rest, and so that column ends up wrapping if equal column widths are imposed.
If I have a tabular of the form:
\begin{tabular}{|c|c|c|c|c|} Somewhat longer column heading & $x$ & $y$ & $z$ \\ \hline A long but one-line description & 3.1 & 4.1 & 5.9 \\ Another long-ish description that shouldn't crash & 2.7 & 1.8 & 2.8 \end{tabular} Then what I'm looking for is something like:
where I've marked the page margins in red. (Number alignment is slightly off because I faked this by adding a bunch of ~s.)
(The numbers are simplified; in reality they will be a mix of integers and numbers with error bars, so I can't use d columns to align on the decimal point.)
Thing that don't work
tabular*
Trying this solution comes close, but no space is added at the left, and inter-column lines are misplaced.
\begin{tabular*}{\textwidth}{@{\extracolsep{\fill}}|c|c|c|c|c|} tabularx
tabularx appears to only be able to set even widths, not spacings, so the left column wraps and the right columns get too much space:
Preamble:
\newcolumntype{Y}{>{\centering\arraybackslash}X} Table header:
\begin{tabularx}{\textwidth}{|Y|Y|Y|Y|Y|} tabulary
tabulary seems to ignore the {\textwidth} option; I'm not sure if this is a bug.
\begin{tabulary}{\textwidth}{|C|C|C|C|C|} tabularray
LaTeX3's tabularray/tblr comes close setting the relative column widths to -1, but it seems to act multiplicatively rather than additively, so the wide column gets too much space.
\begin{tblr}{width=\textwidth,colspec={|X[-1,c]|X[-1,c]|X[-1,c]|X[-1,c]|}} (Using relative widths of 0 or 1 gives the same problems as tabulary and tabularx above respectively.)
Is there a way to get equal space added per column while still placing the inter-column lines correctly?




