Take the 2-minute tour ×


In a longtable, how do I retrieve the width of the longest line for each column?


I'd like to use the longtable environment in combination with the ltablex package. The latter allows for weighting the columns, such that column 2 is twice as large as column 1, for instance.

I have many tables to format, and due to their data source it's not possible to give the tables any hint on column widths. As often there is a lot of text in one or two columns, but little text in the others, it doesn't make sense to just use X columns. Therefore, I'd like to dynamically adjust the proportions of the table.

My idea is to find the width of the longest line of each column. Using these width it should then be possible to calculate the proportions correctly (while granting each column a mininum width).

Thanks for your help!

share|improve this question
add comment

1 Answer

up vote 2 down vote accepted

That is essentially a description of tabulary as opposed to tabularx so you can look in the source of that package for how to do it, but in particular there is a merge of tabulary and longtable here:

Multi-page with Tabulary?

share|improve this answer
wow, didn't know about tabulary. Thanks for the link! –  Kevin Sep 5 '13 at 11:49
add comment

Your Answer


