Juanjo,
I disagree. The problem and fix I gave are correct. Please let me try to explain in better detail.
With the option 'debugshow', the unfixed tabulary produces the following output with the two tables in my original example:
For the first bad table, we see this (note the line I highlighted in red):
Target Width: 487.8225pt
\tabcolsep: 6.0pt \arrayrulewidth: 0.4pt \doublerulesep: 2.0pt
\tymin: 10.0pt \tymax: 690.0pt
Col 5: Initial=86.63905pt -12.0pt Final=74.63905pt > tymin
Col 4: Initial=77.03896pt -12.4pt Final=64.63896pt > tymin
Col 3: Initial=87.58345pt -12.0pt Final=75.58345pt > tymin
Col 2: Initial=66.86119pt -12.0pt Final=54.86119pt > tymin
Col 1: Initial=218.58371pt -12.0pt Final=206.58371pt > tymin
Line Width: 427.4225pt, Natural Width: 476.30637pt, Ratio: 1
206.58371pt, 54.86119pt, 75.58345pt, 64.63896pt, 74.63905pt,
For the good table, we see this:
Target Width: 487.8225pt
\tabcolsep: 6.0pt \arrayrulewidth: 0.4pt \doublerulesep: 2.0pt
\tymin: 10.0pt \tymax: 690.0pt
Col 5: Initial=82.83351pt -12.0pt Final=70.83351pt > tymin
Col 4: Initial=80.73349pt -12.4pt Final=68.3335pt > tymin
Col 3: Initial=98.1114pt -12.0pt Final=86.1114pt > tymin
Col 2: Initial=70.33347pt -12.0pt Final=58.33347pt > tymin
Col 1: Initial=218.58371pt -12.0pt Final=206.58371pt > tymin
Line Width: 427.4225pt, Natural Width: 490.19559pt, Ratio: 0.87195
180.1303pt, 50.86375pt, 75.08469pt, 59.58327pt, 61.76315pt,
The ratio in the first (bad) case should not be 1. It should be 0.89742.
The bug here is that the comparison was between natural width and the original target line length. The check should be between natural table width and the adjusted target line length, which compensates for the inter-column space requirements. If the natural length is greater than the original line length, as in the good table example above (487 < 490), then the ratio is correct and everything works. So, the bug only bites tables with a natural width that falls between the original target line length and original target line length less the inter-column space. This is indeed the case in the first example (427 < 476 < 487)
The fixed code now gives the correct behavior for the bad table:
Target Width: 487.8225pt
\tabcolsep: 6.0pt \arrayrulewidth: 0.4pt \doublerulesep: 2.0pt
\tymin: 10.0pt \tymax: 690.0pt
Col 5: Initial=86.63905pt -12.0pt Final=74.63905pt > tymin
Col 4: Initial=77.03896pt -12.4pt Final=64.63896pt > tymin
Col 3: Initial=87.58345pt -12.0pt Final=75.58345pt > tymin
Col 2: Initial=66.86119pt -12.0pt Final=54.86119pt > tymin
Col 1: Initial=218.58371pt -12.0pt Final=206.58371pt > tymin
Line Width: 427.4225pt, Natural Width: 476.30637pt, Ratio: 0.89742
185.39134pt, 49.23326pt, 67.82973pt, 58.00798pt, 66.98221pt,
You also said:
In the line right above the one you commented out, there is a length assignment: the value of \TY@linewidth is set equal to \TY@tablewidth. Hence, the test \ifdim\TY@tablewidth <\TY@linewidth is always false. Consequently, the line \def\TY@ratio{1} is never processed and so \TY@ratio is computed somehow.
No, the line above the one I commented out computes the ratio. The test is not always false and only returns a ratio of 1 for tables with a natural width already width less than the target width.
Hope this helps,
-steve