V.Druchkiv
V.Druchkiv

Reputation: 31

Error while using kable with booktabs=TRUE option in R-Studio

Does anyone have problem with compiling .pdf output using kable with booktabs=TRUE option in R Studio? Without booktabs it works just fine. When I try to improve the table format adding booktabs=TRUE to kable, I get an error "! Illegal unit of measure (pt inserted)." followed by message of pandoc "Error: pandoc document conversion failed with error 43".

My code is:

kable(table, col.names = c("Groups", "N","% Cum", "%", "N","% Cum.", "%"),
      caption="Some Caption",row.names = FALSE,align="c",
      format ="latex", booktabs=FALSE)  %>%
      add_header_above(c(" ", "Group 1" = 3, "Group 2" = 3)) %>%
      kable_styling(latex_options = c("striped", "hold_position"))

Upvotes: 3

Views: 1795

Answers (2)

John J.
John J.

Reputation: 1716

I had the same problem (error 43). In my case, it was because at least one of my rows began with a bracket [. Once I removed this it compiled the pdf as usual.

Upvotes: 1

Cedric
Cedric

Reputation: 2474

You need to add a call to the booktabs package in LATEX. Add this to your preamble

---
output: pdf_document
header-includes:
  - \usepackage{booktabs}
---

Upvotes: 1

Related Questions