4

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?

5
  • Not taking into account \tabcolsep (the distance between the column border and its content.) Sep 11, 2013 at 0:15
  • Didnt even know something like that exists... Thanks!
    – Shiuyin
    Sep 11, 2013 at 0:16
  • 1
    Also, use \begin{tabular}{|*{17}{p{0.6cm}|}} ... \end{tabular} Writing p{0.6cm} 17 times is exhausting and prone to error. Sep 11, 2013 at 0:17
  • @GonzaloMedina it's almost a duplicate but with the extra complication of | here. (Although surely that must already be on the site somewhere...) Sep 11, 2013 at 0:31

2 Answers 2

6

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.

3
  • Perhaps you meant 0.6cm instead of 6.5cm in two different places in your answer? Sep 11, 2013 at 1:22
  • I understand what you mean, hoever copying this doesn't help me and only outputs Errors like "Illegal uni of measure (pt inserted)". You forgot\multicolumn{2} to say that 2 cells are combined, but it still doesnt work ...
    – Shiuyin
    Sep 11, 2013 at 13:24
  • @Shiuyin It was late (and you had not provided a test file, which always helps) sorry there was a syntax error, fixed now (0.6cm)*2 not 2*(0.6cm) e-tex expression syntax is a little restrictive sometimes:-) Sep 11, 2013 at 13:34
0

You need to include the column separation value.

You should try

\dimexpr1.6cm+2\tabcolsep
0

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.