kableExtra
kableExtra copied to clipboard
Problems with `&` in cell text with linebreak
Hao, thank you for kableExtra
. I started to use it just 3 weeks ago and I can't live without it anymore ;-)
I encountered a problem using linebreak, whenever an ampersand is a part of the text in a table cell. For instance, using your example in Insert linebreak in table results in the following error:
! Extra alignment tab has been changed to \cr.
<template> ...egin \relax \d@llarend \endtemplate
As for a reproducible example: The code I have used:
library(knitr)
library(kableExtra)
dt_lb <- data.frame(
Item = c("Hello\nWorld", "This & is\na cat"),
Value = c(10, 100)
)
dt_lb %>%
mutate_all(linebreak) %>%
kable(booktabs = T, escape = F,
col.names = linebreak(c("Item\n(Name)", "Value\n(Number)")))
@petzi53 Thank you very much for your kind words and for reporting this bug! I will add an escape
option to linebreak and turn it on as default. 👍
Hi Peter, in the meantime I get around this by double-escaping the ampersand:
Item = c("Hello\nWorld", "This \\& is\na cat")