我试图使用huxtable套餐制作一张桌子,但我遗漏了一些内容:
首先,我尝试了以下代码(这是git中的示例):
<<test>>=
color_demo <- matrix('text', 7, 2)
rainbow <- c('red', 'orange', 'yellow', 'green', 'blue', 'turquoise', 'violet')
color_demo <- as_hux(color_demo) %>%
set_text_color(rainbow) %>% # text rainbow goes down columns
set_background_color(rainbow, byrow = TRUE) %>% # background color rainbow goes along rows
set_all_borders(1) %>%
set_all_border_colors('white') %>%
print_latex()
@
其中产生了以下输出,表格内容使用双##
字符进行了转义。
我还尝试使用asis
chunk选项,但后来我获得了以下内容,因此测试可能无意使用此选项运行:
这是我可重现的代码:
\documentclass[a4paper]{article}
\title{test for huxtable}
\begin{document}
\maketitle
<<load_libraries, echo = FALSE, eval = TRUE, results ="hide">>=
library(knitr)
library(huxtable)
@
<<test>>=
color_demo <- matrix('text', 7, 2)
rainbow <- c('red', 'orange', 'yellow', 'green', 'blue', 'turquoise', 'violet')
color_demo <- as_hux(color_demo) %>%
set_text_color(rainbow) %>% # text rainbow goes down columns
set_background_color(rainbow, byrow = TRUE) %>% # background color rainbow goes along rows
set_all_borders(1) %>%
set_all_border_colors('white') %>%
print_latex()
@
<<test2,results ="asis">>=
color_demo <- matrix('text', 7, 2)
rainbow <- c('red', 'orange', 'yellow', 'green', 'blue', 'turquoise', 'violet')
color_demo <- as_hux(color_demo) %>%
set_text_color(rainbow) %>% # text rainbow goes down columns
set_background_color(rainbow, byrow = TRUE) %>% # background color rainbow goes along rows
set_all_borders(1) %>%
set_all_border_colors('white') %>%
print_latex()
@
\end{document}