gpt4 book ai didi

r - kableExtra addfootnote general spanning multiple lines with PDF (LaTeX) 输出

转载 作者:行者123 更新时间:2023-12-05 01:30:22 25 4
gpt4 key购买 nike

问题

代码

# Toy Data
ID <- c(paste("G0", as.character(1:9), sep = ""),"G10","G11","Mean")
V1 <- c(10.06,11.06,12.06,13.06,14.06,15.06,16.06,17.07,18.07,19.07,6.88,13.86)
V2 <- c(0.21,0.03,0.09,0.03,0.09,0.03,0.09,0.03,0.09,0.21,0.31,NA)
tbl <- data.frame(ID, V1, V1, V2, V1, V2, V1, V2, V2)
colnames(tbl) <- c('ID','Get. \\%','Get. \\%','K','Get. \\%','K','Get. \\%','K','P')

# Specify kable NA value and load kableExtra
options(knitr.kable.NA = '--')
require(kableExtra)

# Generate table for PDF output (LaTeX)
kbl(tbl, format = 'latex', align = 'l', booktabs = T, escape = F, digits = 2,
linesep = "", caption = "This is a table caption.") %>%
add_header_above(c(" ", "AB", "BP" = 2, "CK" = 2, "JAM" = 2, ""), bold = T) %>%
column_spec(1, width = '1.15cm') %>%
row_spec(11, hline_after = T) %>%
row_spec(12, bold = T) %>%
kable_styling(position = "center", latex_options = "hold_position") %>%
footnote(general_title = "Note.", footnote_as_chunk = T,
general = "Relatively long footnote that I would like to span
a couple of lines. Relatively long footnote that I
would like to span a couple of lines.")

输出

enter image description here

评论

问题 1: 输出在脚注中显示“makecell[1]”,我显然不希望包括在内。添加参数 escape = T 并没有像我预期的那样解决这个问题。

N.B. 通过设置 footnote_as_chunk = F,这个问题得到了解决,但是在字幕开始之前引入了一个换行符的不良影响。彼得在下面的回答证明了这一点。

问题2 脚注不想被表格的长度所限制。我想也许可以在脚注字符串中手动添加换行符,但这似乎是一种乏味的解决方法,我希望有一种方法可以更有效地实现这一点。 documentation 显示(参见表 4,第 25 页)一个示例,说明如何规避此问题,但缺少代码。

编辑:此问题(#2)已通过在调用 kbl 时设置 threeparttable = T 解决。

用 pdflatex 或 xelatex 编译似乎没有任何区别。任何见解将不胜感激。

最佳答案

试试这个:


library(kableExtra)
library(magrittr)

kbl(tbl,
format = 'latex',
longtable = TRUE,
align = 'l',
booktabs = T,
escape = F,
digits = 2,
linesep = "",
caption = "This is a table caption.") %>%
add_header_above(c(" ", "AB", "BP" = 2, "CK" = 2, "JAM" = 2, ""), bold = T) %>%
column_spec(1, width = '1.15cm') %>%
row_spec(11, hline_after = T) %>%
row_spec(12, bold = T) %>%
kable_styling(position = "center", latex_options = "hold_position", full_width = FALSE) %>%
footnote(general_title = "Note.",
footnote_as_chunk = TRUE,
threeparttable = TRUE,
general = "Relatively long footnote that I would like to span a couple of lines. Relatively long footnote that I would like to span a couple of lines.")

footnote_as_chunk = TRUE 使用“常规”脚注选项“Note”。和“脚注....”文本在同一行开始。如下图所示。

enter image description here

关于r - kableExtra addfootnote general spanning multiple lines with PDF (LaTeX) 输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67155247/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com