【发布时间】:2021-02-04 03:43:11
【问题描述】:
我按照以下最小示例在 LyX 2.3.6 / TeX Live 2020 中创建一个表:
<<results = "asis",echo = F, warning = FALSE, tidy=FALSE>>=
library(dplyr)
library(kableExtra)
df <- data.frame(Female = c(1.52, -0.03), Male = c(1.34, -0.02) )
rownames(df) <- c("Apples", "Bananas")
kable(df, format = "latex", booktabs = T, linesep = "", row.names = TRUE,
align = c("l", "r", "r"), escape = FALSE) %>%
kable_styling("striped", full_width = F, font_size = 10 )
@
这打印得很完美(它在页面上居中),但我无法控制列宽。如果我用 column_spec 语句添加一行,我会收到一个我不理解的错误。如果块被扩展为读取
<<results = "asis",echo = F, warning = FALSE, tidy=FALSE>>=
library(dplyr)
library(kableExtra)
df <- data.frame(Female = c(1.52, -0.03), Male = c(1.34, -0.02) )
rownames(df) <- c("Apples", "Bananas")
kable(df, format = "latex", booktabs = T, linesep = "", row.names = TRUE,
align = c("l", "r", "r"), escape = FALSE) %>%
kable_styling("striped", full_width = F, font_size = 10 ) %>%
column_spec(1, width = "6 em")
@
表格现在左对齐,不在页面中心,所有列都居中而不是左右对齐,字母“c”打印在表格上方,错误日志显示以下消息:
! Undefined control sequence.
<argument> >{\raggedright \arraybackslash
}p{6em}lr
l.149 ...}{>{\raggedright\arraybackslash}p{6em}lr}
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., `I\hbox'). Otherwise just continue,
and I'll forget about whatever was undefined.
! LaTeX Error: Illegal character in array arg.
See the LaTeX manual or LaTeX Companion for explanation.
Type H <return> for immediate help.
...
l.149 ...}{>{\raggedright\arraybackslash}p{6em}lr}
You're in trouble here. Try typing <return> to proceed.
If that doesn't work, type X <return> to quit.
! LaTeX Error: Illegal character in array arg.
See the LaTeX manual or LaTeX Companion for explanation.
Type H <return> for immediate help.
...
l.149 ...}{>{\raggedright\arraybackslash}p{6em}lr}
You're in trouble here. Try typing <return> to proceed.
If that doesn't work, type X <return> to quit.
[2] (./Kable_Explorations.aux)
Package rerunfilecheck Info: File `Kable_Explorations.out' has not changed.
(rerunfilecheck) Checksum: D41D8CD98F00B204E9800998ECF8427E;0.
)
我非常感谢您就问题的根本原因以及如何解决问题提供任何帮助和指导。
真诚的
托马斯·飞利浦
【问题讨论】:
标签: r formatting kableextra lyx