# Tabularx with calculated column widths that use the whole table width

I am currently searching for a potential tabu replacement (see Tabu command replacement) but wasn't able to find any solution.

So instead of a command replacement I am now searching for something to be at least able to replace the tabus itself. I found some solutions for minor issues as the \extrarowsep and the math-mode-columns. However, I wasn't able to get any acceptable results for the automatic column width generation in combination with a given table width. I checked tabular, tabular*, tabularx and tabulary and didn't get the wanted result. Let me give you an MWE describing my problem:

\documentclass[11pt,a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{tabularx}

\begin{document}
1

\begin{tabular}{|>{$}l<{$}|l|l|l|}
\hline
x\, \in & A & B & C\\\hline
\end{tabular}\vspace{2cm}

2

\begin{tabularx}{0.7\linewidth}{|>{$}l<{$}|l|l|l|}
\hline
x\, \in & A & B & C\\\hline
\end{tabularx}\vspace{2cm}

3

\begin{tabularx}{0.7\linewidth}{|>{$}X<{$}|X|X|X|}
\hline
x\, \in & A & B & C\\\hline
\end{tabularx}\vspace{2cm}

4

\begin{tabularx}{0.7\linewidth}{|>{$}X<{$}|l|l|l|}
\hline
x\, \in & A & B & C\\\hline
\end{tabularx}
\end{document}


So table number 1 gives the wanted feature of automatically calculated column widths. But as far as I undestood I can not give a desired table width. That is possible with tables 2, 3 and 4. But as you can see there the problems are:

• all l columns (2): they calculate the needed column width but don't use the whole table width
• all X columns (3): they use the table width but are all the same size (as I understood: the table width is equally parted between all X columns)
• one X and the rest l columns (4): slightly better; now the whole table width is used, the l columns have nice calculated widths and the X column uses the rest. Three problems with that:
1. I always have to include different column types
2. this might be okay for the given example but doesn't look nice for a table width of 0.4\linewidth or \linewidth
3. No flexibility over the widths of the X columns without huge (and individual for every tabu) extra definitions.

Long story short: None of these examples give me the same result as

\begin{tabu}to 0.7\linewidth{|X[-1l]|X[-1l]|X[-1l]|X[-1l]|}


would have given me (table width 0.7\linewidth and reasonable but dynamically scale columns, all with the same construction parameter [-1l])

Now am I missing something? I also found some nice extra definitions as \hsize and \columnfill but have no idea how to construct the wanted behaviour.

• For this specific example \begin{tabularx}{0.7\linewidth}{|>{$}l<{$}|X|X|X|} \hline x\, \in & A & B & C\\\hline G_{g} & links unten & rechts oben & links unten\\\hline \end{tabularx} should give you a result close to the tabu one. However, this approach definitely isn't generally applicable. Dec 19, 2020 at 13:23

It’s easy peasy with tblr environment of the new LaTeX3 package tabularray:
\documentclass{article}