用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标题‘) %>%
Set_label(“选项卡:hux标签”)
if (knitr::is_html_output()) {
print_html(hux) # output table html友好(需要在块选项“结果=‘asis’”中)
}
if (knitr::is_latex_output()) {
胡克斯
}
我不确定是否建议使用huxtable提供的标题和标签命令。
set_caption('pipe caption') and set_label("tab:hux-label") 或针织品
chunk-label and fig.cap='chunk caption'就数字而言,后者工作得很好,但不幸的是,对表格来说却不是这样。
"tab.cap“的钩子,如下面所讨论的,并不适用于预订,如果需要PDF & HTML的话。Using table caption on R markdown file using knitr to use in pandoc to convert to pdf
非常感谢您的帮助和建议!
发布于 2018-11-16 11:37:01
如果您升级到huxtable 4.3.0 (现在是CRAN),它会自动为您处理预订表标题。下面是一个简短的例子:
---
title: "Bookdown test"
output:
bookdown::pdf_book: default
link-citations: yes
---
```{r setup, include=FALSE}图书馆(Dplyr)
图书馆(Huxtable)
Knitr::opts_chunk$set(回声=假)
My table is \@ref(tab:foo1). The other table is \@ref(tab:foo2). The third is \@ref(tab:foo3).
```{r}hux(a = 1:5,b= 1:5) %>%
Set_caption(“我的标签表”) %>%
Set_label(“选项卡:foo1 1”)
hux(a = 1:5,b= 1:5) %>%
Set_caption(“我的无标签表”)
hux(a = 1:5,b= 1:5) %>%
Set_caption(“我的标签表,前缀应该自动添加!”) %>%
set_label("foo2")
%>% (a=“没有标题但有标签的表”)
Set_label(“选项卡:foo3 3”)
hux(a =“没有标题或标签的表”)
不是一切都是完美的。如果设置echo = TRUE,则需要在\usepackage{fancyvry}头中手动插入\usepackage{fancyvry}之前的TeX。
https://stackoverflow.com/questions/52868415
复制相似问题