使xtable适合pdf文件

use*_*980 4 latex r sweave

我正在创建一个使用xtable来创建表格并放入pdf文件的sweave文档。它可以工作,但是表格不适合该文档,并且缺少一些文本。有没有一种方法可以使xtable中的文本对齐/使xtable完全适合pdf文件?

这是我的数据:

dput(x)
structure(list(App = structure(c(3L, 2L, 1L), .Label = c("AppServer", 
"Db", "Web"), class = "factor"), Group = structure(c(2L, 1L, 
1L), .Label = c("Back", "Front"), class = "factor"), Owner = structure(c(1L, 
1L, 1L), .Label = "Infrasructure", class = "factor"), Server = structure(1:3, .Label = c("ServerA", 
"ServerB", "ServerC"), class = "factor"), NumberCPU = c(64L, 
120L, 120L), Description = structure(c(1L, 3L, 2L), .Label = c("Front End server to server web traffic", 
"Hold Web templates to generate dynamic content", "Keeps customer data and login information"
), class = "factor"), Cost = structure(1:3, .Label = c("$200,000 ", 
"$400,000 ", "$500,000 "), class = "factor")), .Names = c("App", 
"Group", "Owner", "Server", "NumberCPU", "Description", "Cost"
), class = "data.frame", row.names = c(NA, -3L))
Run Code Online (Sandbox Code Playgroud)

这是将表格放入pdf的代码:

print(xtable(x, caption=paste("Summary of applications"),table.placement="!h",caption.placement="top", align=c('l', 'p{1.5in}', rep('c',6) )))
Run Code Online (Sandbox Code Playgroud)

Chr*_*h_J 5

我建议您查看xtable gallery,这里有很多有用的示例。基本上,如果您不想通过缩短字符串来调整表格,我会看到两个选择:

  1. 使用较小的字体。
  2. 使用横向模式。

在这里,我将两者结合使用:

\documentclass{article}
\usepackage{rotating}

\begin{document}

<<Data,echo=FALSE>>=
library(xtable)
x <- structure(list(App = structure(c(3L, 2L, 1L), .Label = c("AppServer", 
"Db", "Web"), class = "factor"), Group = structure(c(2L, 1L, 
1L), .Label = c("Back", "Front"), class = "factor"), Owner = structure(c(1L, 
1L, 1L), .Label = "Infrasructure", class = "factor"), Server = structure(1:3, .Label = c("ServerA", 
"ServerB", "ServerC"), class = "factor"), NumberCPU = c(64L, 
120L, 120L), Description = structure(c(1L, 3L, 2L), .Label = c("Front End server to server web traffic", 
"Hold Web templates to generate dynamic content", "Keeps customer data and login information"
), class = "factor"), Cost = structure(1:3, .Label = c("$200,000 ", 
"$400,000 ", "$500,000 "), class = "factor")), .Names = c("App", 
"Group", "Owner", "Server", "NumberCPU", "Description", "Cost"
), class = "data.frame", row.names = c(NA, -3L))
@

<<tab,echo=FALSE,results='asis'>>=
print(xtable(x, caption=paste("Summary of applications"),
             caption.placement="top",
             align=c('l', 'p{1.5in}', rep('c',6))),
             size="footnotesize",
             floating.environment="sidewaystable")
@


\end{document}
Run Code Online (Sandbox Code Playgroud)

请注意,您必须使用LaTex软件包rotating。这应该给你这样的东西:

输出量