39

In a knitr/Sweave report, the kable function of knitr with the option booktabs=TRUE adds a \addlinespace each fifth line:

P1 & A & 10 & 11.016181 & 110.16181 & 44.95101 & 269.9745\\
P1 & B & 10 & 8.592386 & 85.92386 & 35.06083 & 210.5743\\
P1 & A & 100 & 120.610305 & 120.61031 & 58.61274 & 248.1857\\
P1 & B & 100 & 94.990728 & 94.99073 & 46.16245 & 195.4671\\
P2 & A & 1000 & 698.097191 & 69.80972 & 37.34843 & 130.4846\\
\addlinespace
P2 & B & 1000 & 837.649249 & 83.76492 & 44.81452 & 156.5690\\
P2 & A & 10000 & 10356.365176 & 103.56365 & 49.47422 & 216.7883\\
P2 & B & 10000 & 10214.989594 & 102.14990 & 48.79884 & 213.8289\\
\bottomrule

Is it possible to get rid of these \addlinespace's while still using the option booktabs=TRUE?

CL.
  • 14,577
  • 5
  • 46
  • 73
Stéphane Laurent
  • 75,186
  • 15
  • 119
  • 225
  • 1
    @Yihui Thank you, this is really generous! – CL. Aug 03 '17 at 15:06
  • 2
    @CL. I don't care about these virtual points. I don't often start a bounty. When I do, I almost always offer the maximum possible points. You saved me two minutes, and these two minutes are totally worth 500 points. – Yihui Xie Aug 04 '17 at 02:01

1 Answers1

74

You can add the argument linesep = "" to kable. This will be passed on to kable_latex where it overwrites the default

linesep = if (booktabs) c('', '', '', '', '\\addlinespace') else '\\hline'

Example:

kable(cars, format = "latex", booktabs = TRUE, linesep = "")
CL.
  • 14,577
  • 5
  • 46
  • 73
  • excelent, I did not know that kable command pass latex commads as is. – Captain Tyler Mar 01 '18 at 15:17
  • 3
    Can I specify, in a vector, how much vertical space I want between each row seperately when working with 'kableExtra' and Latex for creating pdf's? Or is this a question which should be asked seperately? – Benjamin Telkamp Apr 03 '18 at 17:34