r - kableExtra:如果一个表中包含多个数据帧,则 short.caption 参数不起作用
问题描述
我最近注意到,如果命令中包含多个数据帧,则 kableExtra 包中的 kable() 行为会很奇怪。
不使用 Short.caption 参数
在此示例中,我创建了两个数据框并希望将它们包含在一个表中。
library(kableExtra)
t1 <- c(68, 48, 50, 113, 98, 94)
t2 <- c(26, 16, 22, 30, 16, 12)
Group <- c("b1", "b2", "b3", "b4", "b5", "b6")
cows <- data.frame(Group, t1, t2)
colnames(cows) <- c("Group", "t1", "t2")
kable(list(cows[1:3,], cows[4:6,]),
format = "latex",
caption= "Number of some variables used in some groups",
caption.short = "Anything shorter.",
booktabs = T, row.names = F) %>%
kable_styling(latex_options = c("striped", "hold_position"))
假设\listoftables
包含在 Rmarkdown 文件的开头,它将无法识别短标题。如果我查看实际的 Latex 代码,则不包括 [Anything Short.]:
\begin{table}[!h]
\caption{\label{tab:}Number of some variables used in some groups}
\centering
\begin{tabular}[t]{lrr}
\toprule
Group & t1 & \vphantom{1} t2\\
\midrule
\rowcolor{gray!6} b1 & 68 & 26\\
b2 & 48 & 16\\
\rowcolor{gray!6} b3 & 50 & 22\\
\bottomrule
\end{tabular}
\centering
\begin{tabular}[t]{lrr}
\toprule
Group & t1 & t2\\
\midrule
\rowcolor{gray!6} b4 & 113 & 30\\
b5 & 98 & 16\\
\rowcolor{gray!6} b6 & 94 & 12\\
\bottomrule
\end{tabular}
\end{table}
如果我排除一个表,则会出现 [Anything short.] 参数:
library(kableExtra)
t1 <- c(68, 48, 50, 113, 98, 94)
t2 <- c(26, 16, 22, 30, 16, 12)
Group <- c("b1", "b2", "b3", "b4", "b5", "b6")
cows <- data.frame(Group, t1, t2)
colnames(cows) <- c("Group", "t1", "t2")
kable(cows[4:6,],
format = "latex",
caption= "Number of some variables used in some groups",
caption.short = "Anything shorter.",
booktabs = T, row.names = F) %>%
kable_styling(latex_options = c("striped", "hold_position"))
乳胶代码:
\begin{table}[!h]
\caption[Anything shorter.]{\label{tab:}Number of some variables used in some groups}
\centering
\begin{tabular}[t]{lrr}
\toprule
Group & t1 & t2\\
\midrule
\rowcolor{gray!6} b4 & 113 & 30\\
b5 & 98 & 16\\
\rowcolor{gray!6} b6 & 94 & 12\\
\bottomrule
\end{tabular}
\end{table}
我在 row_spec() 和 add_header_above() 功能中遇到了类似的行为。到目前为止,我已经手动插入了相关的 Latex 代码以适应我的工作,但我想知道其他人是否有类似的问题。
我想知道这个问题是源于我这边的错误还是 kableExtra 包中的潜在问题。
解决方案
推荐阅读
- python - 在第二次出现子字符串后打印字符串的其余部分
- sql-server - Grails 无法使用 SQL Server 数据库将序列下一个值分配给字段
- javascript - ActionChain onclick().perform() 后 Python selenium 进程退出
- report - 元数据库中的警报 - 基于输入变量的报告
- python - 在 Python 中将大字节字符串转换为二进制字符串数组的更快方法
- python - 如何在查找键盘输入时更新 Tkinter 标签
- java - 使用 Apache JMeter 进行多体压力测试 POST
- python - TypeError:参数类型不正确(预期为 numpy.ndarray,得到 numpy.bool_)
- c# - 如何在 C# 上使用数据库数据获取组合框上的范围值
- autocad - CIVIL 3D,正在处理走廊时的重叠横截面