使用 Knitr 创建 Xtable 时,指定大小后出现额外的花括号

使用 Knitr 创建 Xtable 时,指定大小后出现额外的花括号

我正在使用 knitr 创建 R Markdown 文档,在使用 xtable 创建表格时遇到了麻烦。我的表格非常大,我试图使用 print 语句中的 size 命令来减小大小。我遇到的问题是,该命令似乎添加了两个额外的花括号,它们显示在 pdf 中,一个在表格之前,一个在表格之后。

有谁知道如何解决这个问题?

梅威瑟:

---
title: ''
graphics: yes
header-includes:
- \usepackage{graphicx}
- \usepackage{fancyhdr}
- \usepackage{xcolor}
- \fancyfoot[LE,RO]{SIG}
- \usepackage{colortbl}
- \usepackage{booktabs}
- \definecolor{cobalt}{RGB}{0, 91, 187}
- \usepackage{pdflscape}
- \usepackage{fullpage}
- \usepackage{helvet}
- \renewcommand{\familydefault}{\sfdefault}
output: 
  pdf_document: 
    keep_tex: yes
tables: yes
geometry: margin=2cm
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```


```{r kablesum, results='asis', echo=FALSE, warning=FALSE, fig.align='left', out.width='10in',fig.width=16,fig.height=9}
library(plyr)
library(knitr)
library(pander)
library(xtable)
library(gridExtra)

library(ggplot2)
library(ggthemes)


summaryterms=data.frame(matrix(c(1:18),nrow=2))

options(scipen=4,digits=2)


my.df=summaryterms

glossaryprint<-xtable(my.df,caption="Summary of Terms")

bold <- function(x) {paste('{\\textbf{',x,'}}', sep ='')}

align(glossaryprint)<-"lp{0.85in}p{0.75in}p{0.6in}p{0.25in}p{0.3in}p{0.3in}p{1in}p{0.5in}p{1.0in}" #here is the change
print(glossaryprint,tabular.environment="longtable", caption.placement="top", include.rownames = FALSE,comment=FALSE,
      floating=FALSE,
      hline.after=c(-1,nrow(my.df)),
      add.to.row=list(
          pos=list(as.list(c(0,seq(from=1,to=nrow(my.df)-1,by=2))))[[1]],
          command=c("\\hline \\endhead ",
                    rep("\\rowcolor[RGB]{241,242,243}",length(seq(from=1,to=(nrow(my.df)-1),by=2))
      ))),latex.environments = "left",sanitize.colnames.function=bold, size="footnotesize")

``` 

相关内容