4

xtableを使用してテーブルを作成し、PDFファイルに入れるスウィーブドキュメントを作成しています。動作しますが、テーブルがドキュメントに適合せず、一部のテキストが欠落しています。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))

これは、テーブルをpdfに配置するためのコードです。

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

2 に答える 2

5

xtableギャラリーをチェックすることをお勧めします。役立つ例がたくさんあります。基本的に、文字列を短くしてテーブルを調整したくない場合は、次の2つのオプションがあります。

  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}

LaTexパッケージを使用する必要があることに注意してくださいrotating。これにより、次のような結果が得られます。

出力

于 2013-03-26T19:35:03.570 に答える
1

別の解決策は、いくつかのマークダウンバックエンド(knitrmarkdownまたはpanderパッケージ)を使用し、テーブルを自動的に80文字(または他のユーザー指定の幅)に分割することpanderです。例えば:

> library(pander)
> res <- 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))
> pander(res)

----------------------------------------------------
   App     Group      Owner      Server   NumberCPU 
--------- ------- ------------- -------- -----------
   Web     Front  Infrasructure ServerA      64     

   Db      Back   Infrasructure ServerB      120    

AppServer  Back   Infrasructure ServerC      120    
----------------------------------------------------

Table: Table continues below


---------------------------------------
     Description             Cost  
------------------------------ --------
Front End server to server web $200,000
    traffic                        

Keeps customer data and login  $400,000
       information                     

Hold Web templates to generate $500,000
       dynamic content                 
---------------------------------------

pandocそして、結果は、Rを使用して、またはpanderRから直接使用して、PDFまたはLaTeXに簡単に変換できます。

于 2013-03-26T20:51:03.920 に答える