TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top


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
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

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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