【发布时间】:2017-11-23 20:34:40
【问题描述】:
我正在尝试使用 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 块选项,但随后我得到了以下信息,因此测试可能不适合使用此选项运行:
这是我的可重现代码:
\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}
【问题讨论】:
-
您的“asis”版本,在 PDF 中右侧有 2 个彩色列,但左侧是一系列 5 个倒置的问号,中间散布着三个连字符。日志显示许多错误,以:!未定义的控制序列。
...textwidth }} \par \par \hhline {>{\arrayrulecolor [RGB]{2... l.256 \end{tabularx} 错误顶行末尾的控制序列消息从未被\def'ed。 -
@lawyeR 谢谢,是的,它显然不是要与 asis 一起运行,但是你如何使用它呢?我可能遗漏了一些非常明显的东西。
标签: r latex knitr conditional-formatting