12

longtableオプションを使用してxtableを生成するときに、一番上の行/ヘッダーを設定する方法はありますか?

たとえば、私が持っている場合

tableSb <- xtable(df, caption="A Very Long Table", label="ALongTable")
print(tableSb, include.rownames=TRUE, tabular.environment="longtable", floating=FALSE)

これは正常に機能しますが、テーブルが新しいページにロールオーバーすると、ヘッダーは繰り返されません。助言がありますか ?

4

2 に答える 2

27

これを実現するにadd.to.rowは、関数のオプションを使用する必要がありprintます(詳細については実行?print.xtableしてください)。

これを試してください(R-Forgeの投稿から採用)

addtorow          <- list()
addtorow$pos      <- list()
addtorow$pos[[1]] <- c(0)
addtorow$command  <- c(paste(
  "\\hline \n",
  "\\endhead \n",
  "\\hline \n",
  "{\\footnotesize Continued on next page} \n",
  "\\endfoot \n",
  "\\endlastfoot \n",
  sep=""))
x.big <- xtable(
  x,
  label = "tabbig",
  caption = "Example of longtable spanning several pages")
print(
  x.big,
  tabular.environment = "longtable",
  floating = FALSE,
  include.rownames = FALSE,  # because addtorow will substitute the default row names 
  add.to.row = addtorow,     # this is where you actually make the substitution
  hline.after=c(-1))         # because addtorow will substitute the default hline for the first row

それは解決策の少し不器用ですが、少なくともそれはあなたにたくさんのカスタマイズを提供します。

于 2012-02-19T15:42:27.593 に答える
2

print.xtableのコードを見ると、次の場合に考慮されるのtabular.environment="longtable"

  • 設定した場合も警告を発するfloating=TRUE
  • ロングテーブルの適切な場所にキャプションを配置する(上または下)

後続のページでヘッダーを繰り返すための固有のコードは出力されません。パッケージをチェックしてくださいlatexHmiscロングテーブルもサポートされていることは知っていますが、ヘッダーが正しく繰り返されているかどうかは思い出せません。

于 2011-09-16T20:50:55.217 に答える