尽管How to set both column width and text alignment in align argument of xtable?中描述的问题看起来相同,但解决方案看起来很有希望,但我无法解决这个问题。
---
output: pdf_document
header-includes:
- \usepackage{longtable}
- \newcolumntype{R}[1]{>{\raggedleft\let\newline\\\arraybackslash\hspace{0pt}}p{#1}}
---
```{r, results='asis', echo=FALSE, warning=FALSE}
library(xtable)
options(xtable.comment = FALSE)
addtorow <- list()
addtorow$pos <- list()
addtorow$pos[[1]] <- c(0)
addtorow$command <- c(paste("\\hline \n",
"\\endhead \n",
"\\hline \n",
"{\\footnotesize See next page} \n",
"\\endfoot \n",
"\\endlastfoot \n",
sep=""))
irisShort <- head(iris)
print(xtable(irisShort,
digits=rep(0,6),
align=c(
"p{0.015\\textwidth}|",
"R{0.37\\textwidth}|",
"R{0.12\\textwidth}|",
"R{0.08\\textwidth}|",
"R{0.02\\textwidth}|",
"p{0.35\\textwidth}|")))
```
在我的示例中,newcolumntype声明似乎是错误的,但我不知道如何修复它。我得到的错误是:
! Undefined control sequence.
<recently read> \newcolumntype
任何想法如何解决?