1

I'm creating a R Markdown document using knitr and am running into trouble using xtable to create a table. My table is very large and I'm trying to reduce the size using the size command in the print statement. The issue I'm running into is that the command seems to add two extra curly braces which show up in the pdf, one before the table and one after.

Does anyone know a way to fix this?

MWE:

---
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")

``` 
1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.