Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Is there a way to determine the width of the first column in a tabular enviroment?

I've thought about using a savebox but that would only give me the size of the text (and in one cell only), not the actual column width.

Or should I use longtable (or another package) to do that?

share|improve this question
Might be an idea to tell us what you are trying to do. Then we can figure out a good solution. –  daleif Jan 7 at 10:44
yes, tell us a higher level picture. maybe you don't even need the size of the column. –  Billiska Jan 7 at 12:02

2 Answers 2

up vote 8 down vote accepted

This has some limitations on the tabular: you can't have \multicolumn in the last row, nor optional arguments to \\ (this one may be lifted off).



  \def\@temp{\else\@latex@warning{No such column}\fi}


abc & def & ghi \\
ABC & \multicolumn{2}{c}{aaa} \\
1 & 12 & 123

The width of the first column was \foo{1}

The width of the second column was \foo{2}

The width of the third column was \foo{3}


It works by first typesetting the table in a “reduced” form, then taking off its last row and dismantling it bit by bit. The last argument to mtabular is a macro name that can later be used with a numeric argument for getting the relative column width.

enter image description here

share|improve this answer
+1 for being first, but mine's simpler:-) –  David Carlisle Jan 7 at 13:19
+1 and accepted, thanks. But shouldn't there be % at the end of the line before \endgroup. I think this might cause some unwanted spacing. –  masu Jan 7 at 13:51
@SándorKazi Yes, there should be. Still, an use example would be better, to clarify your aims. –  egreg Jan 7 at 13:52
I was just curious if it was possible. Here's what made me curious: tex.stackexchange.com/q/152784/36821 I've constructed an answer for this question based on your solution for this one. –  masu Jan 7 at 15:30

\def\foo#1#2{\ifcsname tpos#1\endcsname\the\dimexpr\csname tpos#2\endcsname sp -\dimexpr\csname tpos#1\endcsname sp\relax\fi}


abc & def & ghi \\
ABC & \multicolumn{2}{c}{aaa} \\
1 & 12 & 123

The width of the first column was \foo{a}{b}

The width of the second column was \foo{b}{c}

The width of the third column was \foo{c}{d}


enter image description here

Slightly different result than egreg, as the code takes a different view of whether tabcolsep padding is included or not.

share|improve this answer
+1, but the user interface is awful. ;-) –  egreg Jan 7 at 13:21
+1, great, but egreg's answer is a little more generic (You have to actually print to table to use this, so it can't effect the the actual table. Or am I mistaken?) –  masu Jan 7 at 13:49
@SándorKazi You can use the lengths within the table, latex will sort itself out on the next run. –  David Carlisle Jan 7 at 14:03

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.