【问题标题】:LyX: kableExtra problem (perhaps a bug) in column_specLyX:column_spec 中的 kableExtra 问题(可能是错误)
【发布时间】: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


    【解决方案1】:

    包的创建者提供了解决方案:他对 column_spec 进行了一些更改以添加条件格式支持并允许将图像插入到列中(请参阅https://haozhu233.github.io/kableExtra/awesome_table_in_html.html#Insert_Images_into_Columns),并且 column_spec() 需要乳胶array 包加载到序言中。如下更新我的 Latex 序言可以完全解决问题:

    \usepackage{array}
    \usepackage{booktabs}
    \usepackage{threeparttablex}
    

    事实上,他建议用户可能想要加载此页面上提到的所有乳胶包 (https://haozhu233.github.io/kableExtra/awesome_table_in_pdf.pdf#page=4),但我发现上面提到的 3 个对于我相对简单的目的来说已经绰绰有余了。

    【讨论】:

      猜你喜欢
      • 2021-04-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-03
      • 2011-07-22
      • 1970-01-01
      • 2018-03-25
      • 2015-03-29
      • 1970-01-01
      相关资源
      最近更新 更多