[Tex/LaTex] LaTeX p cell width

tableswidth

totally new to LaTeX, this question occured today:

I have a table made of 17 columns. Every column is 0,6cm wide.

\begin{tabular}{p{0.6cm}|p{0.6cm}|p{0.6cm}|p{0.6cm}|p{0.6cm}|p{0.6cm}|p{0.6cm}|p{0.6cm}|p{0.6cm}|p{0.6cm}|p{0.6cm}|p{0.6cm}|p{0.6cm}|p{0.6cm}|p{0.6cm}|p{0.6cm}|p{0,6cm}}

That works perfectly and fine. But i also have on several rows 2 cells which are combined with \multicolumn like this:

\multicolumn{2}{|p{1.2cm}|}{\cellcolor{grey}Inverse dependency ratio}

Because this multi column combines two differenct cells i figured out 0,6 + 0,6 = 1,2. Right? So i gave this a width of 1,2cm… However this happens:

enter image description here

The combined \multicolumn doesnt fit to the 2 columns at the bottom of it. What did i do wrong?

Best Answer

It is best to post a complete (small) document showing all packages used however..

Aside from the first column, if you look at

|p{0.6cm}|p{0.6cm}|

and want to span those two columns, the first | is in the previous column so the span should not start with | (unless this is the first column). Then there is padding of \tabcolsep, then column content of 0.6cm, then another \tabcolsep, then |. In the original LaTeX tabular this took no space, but you used \cellcolor so you must have loaded colortbl (or xcolor which loads colortbl) which implies that the array package is loaded. In the array package tabular | takes up the width of the rule \arrayrulewidth, then there is \tabcolsep padding again, 0.6cm of content, \tabcolsep padding, and another | rule .

So you want a

\multicolumn{2}{p{\dimexpr (0.6cm)*2+1\arrayrulewidth+2\tabcolsep\relax}|}{...}

Note this does not have a | on the left and includes the space taken up by the padding and rules between the spanned columns.