簡體   English   中英

Sweave中的xtable:在表格中指定前導或中間規則+對齊

[英]xtable in Sweave: specify toprule or midrule in a table + alignement

我正在使用R中的Sweave生成自動報告。我想:

  1. 在位置(第-1行),我希望有一個中規而不是中規
  2. 將第一行居中對齊,然后將數字右對齊以對齊數字。

這是我的代碼:

\documentclass[a4paper,18pt]{article}
\usepackage[top=2.5cm, left=2.5cm, right=2.5cm,bottom=2.5cm]{geometry}
\usepackage{Sweave} 
\usepackage{booktabs}
\makeatletter
  \def\hrulefill#1{\leavevmode\leaders\hrule\@height#1\hfill \kern\z@}
\makeatother
\begin{document}
\SweaveOpts{concordance=TRUE}

<<xtable1, results=tex,echo=FALSE>>=
library(xtable)

> data
          l w  a m
x     NA  515.0 0.22 127.83
y     NA   75.0 0.45  33.75
z     NA   85.0 0.45  38.25


xtab <- xtable(data)
hline <- c(-1,0,nrow(xtab)-1,nrow(xtab))
align(xtab) <- "lcccc"
print(xtab,booktabs=T,hline.after=hline)
@


\end{document} 

文檔中 ,將add.to.rowhline.after=NULL結合使用,以控制您要添加到hline向量行中的hline

library(xtable)
xtab <- xtable(data)

hline <- c(-1,0,nrow(xtab)-1,nrow(xtab))
htype <- c("\\toprule ", "\\midrule ", "\\toprule ","\\bottomrule ")

print(xtab,add.to.row = list(pos = as.list(hline),
                             command = htype),
      hline.after = NULL)

數據

data <- structure(list(l = c(NA, NA, NA), w = c(515, 75, 85), a = c(0.22, 
0.45, 0.45), m = c(127.83, 33.75, 38.25)), class = "data.frame", row.names = c("x", "y", "z"))

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM