Customize xtable

Viewed 5895

I'd like to customize xtable for export into LaTeX. I know there are some questions abot xtable here, but I couldn't find the specific things I'm looking for.

Here is an example of how my table might look like:

my.table <- data.frame(Specifiers=c("","Spec1", "Spec2", "Spec3"),
    Values1 = c("N=10", 1.03, 1.71, 2.25),
    Values2 = c("N=20", 1.32, 1.79, 2.43))
colnames(my.table)[1] <- ""

Which creates:

         Values1 Values2
1          N=10    N=20
2 Spec1    1.03    1.32
3 Spec2    1.71    1.79
4 Spec3    2.25    2.43

In fact, this table is imported from a .csv-file as data.frame with my.table <- read.delim("filename.csv", sep=",", header=TRUE)

Now I create a LaTeX table with xtable:

latex.tab <- xtable(my.table, caption=c("Stats"))
print(latex.tab, file="Summarystats.tex",
  floating.environment='sidewaystable',
  include.rownames=FALSE,
  booktabs=TRUE,
  latex.environment=NULL)

Here is the resulting LaTeX code:

\begin{sidewaystable}[ht]
\begin{tabular}{lllllll}
  \toprule
 & Values1 & Values2 \\ 
  \midrule
               N=10  &  N=20 \\
     Spec1  &  1.03  &  1.32 \\
     Spec2  &  1.71  &  1.79 \\
     Spec3  &  2.25  &  2.43 \\

   \bottomrule
\end{tabular}
\end{sidewaystable}

Ok, and now this is what I'd like to change:

1) Insert \midrule after the second row instead of after the first. 2) Alternating colours of the rows of this table by inserting \rowcolors{2}{gray!25}{white} within the sidewaystable (or normal table) environment. 3) Rotating column names by 45° 4) Insert \centering instead of the center-environment in cases when I want to center the table.

Any ideas on how to achieve this?

1 Answers
Related