I am using LyX 2.3.6 with TeXLive 2020. I create and print a dataframe using kableExtra - the contents of my table float follow:
<<results = "asis",echo = F, warning = FALSE, tidy=FALSE>>=
library(dplyr)
library(kableExtra)
######## CREATE A TABLE FOR THE BOOK ###########
df_ret_vol <- data.frame(matrix(" ", nrow = 21, ncol = 5))
df_ret_vol$X1 <-c("Australia", "Austria", "Belgium", "Canada", "Denmark", "Finland",
"France", "Germany", "Ireland", "Italy", "Japan",
"Netherlands", "New Zealand", "Norway", "Portugal", "South Africa",
"Spain", "Sweden", "Switzerland", "United Kingdom", "United States")
df_ret_vol$X2 <- c("6.82\%", "0.95\%", "2.61\%", "5.71\%", "5.57\%", "5.48\%",
"3.42\%", "3.32\%", "4.35\%", "2.15\%", "4.21\%", "5.10\%",
"6.43\%", "4.39\%", "3.64\%", "7.09\%", "3.59\%", "5.99\%",
"4.61\%", "5.53\%", "6.51\%")
df_ret_vol$X3 <- c("6.60\%", "0.09\%", "2.99\%", "5.55\%", "5.90\%", "5.43\%",
"3.17\%", "3.42\%", "4.41\%", "2.13\%", "4.38\%", "5.27\%",
"6.06\%", "4.41\%", "3.64\%", "6.09\%", "3.49\%", "5.66\%",
"5.34\%", "5.12\%", "6.51\%")
df_ret_vol$X4 <- c("17.50\%", "30.55\%", "23.35\%", "16.87\%", "20.71\%", "29.49\%",
"22.90\%", "31.32\%", "22.89\%", "28.28\%", "29.19\%", "21.15\%",
"19.22\%", "26.48\%", "33.92\%", "21.90\%", "21.67\%", "21.00\%",
"19.40\%", "19.60\%", "19.93\%")
df_ret_vol$X5 <- c("22.02\%", "37.33\%", "25.62\%", "19.52\%", "22.67\%", "32.12\%",
"28.07\%", "79.02\%", "25.13\%", "32.89\%", "31.36\%", "24.34\%",
"25.14\%", "29.36\%", "40.74\%", "29.26\%", "27.83\%", "23.51\%",
"20.55\%", "22.82\%", "19.93\%")
#Rename columns and reformat the table
colnames(df_ret_vol) <- c("Country", "Local Currency", "U.S. Dollar", "Local Currency", "U.S. Dollar")
kable(df_ret_vol, format = "latex", booktabs = T, linesep = "", row.names = FALSE,
align = c("l", "c", "c", "c", "c"), escape = FALSE) %>%
kable_styling("striped", full_width = F, font_size = 10 ) %>%
add_header_above(c(" " = 1, " Annualized Return" = 2, "Annualized Standard Deviation" = 2)) %>%
add_indent(1:21) %>%
column_spec(1:5, width = "8em")%>%
footnote(general = "Source: Credit Suisse Research Institute Global Investment Yearbook 2020",
general_title = "")
@
If I exclude the column_spec
statement, this produces a table with no problem at all. As soon as I include the column_spec
statement, I get a number of Undefined control sequence
errors with the description
...p{8em}>{centeringarraybackslash}p{8em}}
The control sequence at the end of the top line
of your error message was never def'ed. If you have
misspelled it (e.g., `hobx'), type `I' and the correct
spelling (e.g., `Ihbox'). Otherwise just continue,
and I'll forget about whatever was undefined.
In addition, the first column is now centered, and I see the string "ccccc" above the table. I have looked through the log file, and hunted high and low for the cause of the error, upto and including recreating the file. The fact that I am using "Local Currency" and "U.S. Dollar" twice each seems irrelevant - I get the same error if I use four distinct names.
What might be the cause of my errors?
Many thanks in advance
Thomas Philips