TransWikia.com

Tabularx with calculated column widths that use the whole table width

TeX - LaTeX Asked on February 8, 2021

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 & Chline
G_{g} & links unten & rechts oben & links untenhline
end{tabular}vspace{2cm}

2

begin{tabularx}{0.7linewidth}{|>{$}l<{$}|l|l|l|}
hline
x, in & A & B & Chline
G_{g} & links unten & rechts oben & links untenhline
end{tabularx}vspace{2cm}

3

begin{tabularx}{0.7linewidth}{|>{$}X<{$}|X|X|X|}
hline
x, in & A & B & Chline
G_{g} & links unten & rechts oben & links untenhline
end{tabularx}vspace{2cm}

4

begin{tabularx}{0.7linewidth}{|>{$}X<{$}|l|l|l|}
hline
x, in & A & B & Chline
G_{g} & links unten & rechts oben & links untenhline
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.4linewidth 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.7linewidth{|X[-1l]|X[-1l]|X[-1l]|X[-1l]|}

would have given me (table width 0.7linewidth 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.

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP