I am trying to print a fairly simple table using Rmarkdown LaTex through kable and the kableExtra functions that allow me to bold the rows and columns. Below is an example of my issue:
df <- data_frame(grp=c("<1","1-5","5+"),n=c(3,4,5))
#This works
df %>%
kable(format="latex",booktabs=T)
#This works
df %>%
kable(format="latex",booktabs=T) %>%
kable_styling(latex_options = c("hold_position"))
#This works
df %>%
kable(format="latex",booktabs=T) %>%
kable_styling(latex_options = c("hold_position")) %>%
column_spec(1,bold=T)
#This works
df %>%
kable(format="latex",booktabs=T) %>%
kable_styling(latex_options = c("hold_position")) %>%
row_spec(1 ,bold=T)
#This does not work
df %>%
kable(format="latex",booktabs=T) %>%
kable_styling(latex_options = c("hold_position")) %>%
row_spec(0 ,bold=T) %>%
column_spec(1,bold=T)
Now I was able to figure out it is because my group starts with the less than symbol which apparently is causing chaos when attempting to use both column_spec
and row_spec
. The error message is:
! Misplaced \noalign.
\toprule ->\noalign
{\ifnum 0=`}\fi \@aboverulesep =\abovetopsep \global \@b...
l.129 \toprule
In my actual data frame (which itself isn't much more complicated than this one), my main error is actually Error: \caption outside float
(but I can't seem to replicate it with my MVE, admittedly I left out a few of the other options for this example, though).
I've tried just renaming the group along the lines of \<1
up through \\\\<1
and that either 'works' but prints a slash, or it gives me an error about an unrecognized escape. Now I know that the easiest option is to simply rename the group in some way but I'm interested to see if there is some other escape trick or work around so that I can keep my group name.
Thanks!