I have the following table, but the multicolumn cell width is not the same as the sum of the cells it is combined from.

I assume, this is caused by some margins in each cell, i.e. that the cel width (distance between the two vertical lines) is equal to the set cell width plus some margin - but what is this margin, or what is the easiest way to set the width of the multicolumn cell to be equal to the sum of the widths of the cells it is combined of?




     &  & {March} & {April} & {May}\tabularnewline
    \multicolumn{2}{|c|}{{Species}} & \multicolumn{3}{>{\centering}p{2.7cm}|}{{This is the problem cell, as it has not the width as the ones combined}}\tabularnewline


results in the following table:

results in this table


There is 2*\tabcolsep between each column, and in addition (if using array package) \arrayrulewidth for each vertical rule.

If you load the calc package you could use

  • Nice - works perfectly. But I have many multicolumn cells consisting of different number of cells - Can I use the 'calc' package to write a formula in the preamble, so that I simply have to use 'p{\TheFormula{x}}' where I simply replace x with the number of columns? – Rainer Sep 14 '12 at 12:04
  • well you can write a formula for the correction \def\theformula#1{(#1-1)*(2*\tabcolsep + \arrayrulewidth)} but latex tables don't by default record the p-column widths anywhere so you would need in addition to supply 2.7cm here which here is 3*0.9 but in general would be the sum of the spanned p column widths. – David Carlisle Sep 14 '12 at 12:32
  • OK. I have now \def\mcolWidth#1{(#1*real{0.9})+(#1-1)*(2*\tabcolsep + \arrayrulewidth)} where the 0.9 is the original colum width. In my table I am trying to use p{\mcolWidth{3}} but it doesn't work. What am I missing? – Rainer Sep 14 '12 at 13:12
  • well a \ before real is missing, not sure if calc follows * + precedence it wouldn't hurt to put an extra () from the + to the end. Rather than test it in the table first do \setlength{\dimen0}{....}\showthe\dimen0 and check you get the length expected – David Carlisle Sep 14 '12 at 13:52
  • I am giving up for now with the definition of a formula - I am enter it manually - it is anyway only copy / paste. Thanks a lot. – Rainer Sep 14 '12 at 14:08

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.