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!

1 Answer 1


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?

  • wow, didn't know about tabulary. Thanks for the link! Sep 5, 2013 at 11:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.