【发布时间】:2018-10-18 06:47:39
【问题描述】:
使用 bookdown 编译报告我在引用使用 huxtable 包生成的表格时遇到了困难。对于我的工作,需要创建 LaTex/PDF 以及 HTML 版本的报告。
在渲染文档时 knitr::is_XXX_output() 选择显示表格的最佳方式,请参阅 MWE:
```{r chunk-label, results='asis', fig.cap='chunk-caption'}
set.seed(1234)
dat <- data.frame(cond = factor(rep(c("A","B"), each=2)),
rating = c(rnorm(2),rnorm(2, mean=.8)))
hux <- as_hux(dat) %>%
set_caption('hux caption') %>%
set_label("tab:hux-label")
if (knitr::is_html_output()) {
print_html(hux) # output table html friendly (requires in chunk options "results='asis'")
}
if (knitr::is_latex_output()) {
hux
}
```
不确定是否推荐使用huxtable提供的caption和label命令
set_caption('pipe caption') and set_label("tab:hux-label")
或编织者
chunk-label and fig.cap='chunk caption'
对于数字,后者效果很好,但不幸的是不适用于表格。
下面讨论的“tab.cap”钩子不适用于 bookdown 以及需要 PDF 和 HTML 的情况。 Using table caption on R markdown file using knitr to use in pandoc to convert to pdf
非常感谢您的帮助和建议!
【问题讨论】:
-
我不确定您的实际问题是什么,但这可能是相关的:stackoverflow.com/questions/46318658/…
-
非常感谢@dash2 的回复。我的目标是生成带有标签和标题的 huxtable,它们适用于 HTML 和 LaTeX 输出。在 HTML 中,我可以使用
set_caption('(#tab:setcaption) my caption'),它可以正常工作。在 LaTeX/PDF 中,我可以使用set_caption('(\\#tab:setcaption) caption')——它只适用于一个数字。如果我包括两个数字,我会得到! Package caption Error: \caption outside float.此外,来自 huxtable 包的set_label()没有多大帮助,因为它在 bookdown AFAIK 中不起作用。任何人都有一个想法,也许关于如何规避浮动错误? -
也
hux <- add_footnote(hux, 'my footnote')在 bookdown 中不起作用,产生以下错误:Error in if (! Attr (input, "format")% in% c ("html", "latex")) {: Argument has length 0
标签: r