I would like to change row height such that all rows except the header row will have fix height x and the header row will have eight y. I would like to do this within xtable
environment because I need to generate this table inside a knitr code chunk. I want to retain all other formating used in the code example (each second row gray and the last column in italics).
\documentclass[a5paper]{article}
\usepackage{array}
\begin{document}
<<do_table2, results = "asis">>=
library(xtable)
mydf <- data.frame(id = 1:10, var1 = rnorm(10), var2 = runif(10))
rws <- seq(1, (nrow(head(iris))-1), by = 2)
col <- rep("\\rowcolor[gray]{0.95}", length(rws))
iris$Species <- paste0("\\textit{", iris$Species, "}")
rep("\\[5pt]", nrow(head(iris)))
print(xtable(head(iris)),
add.to.row = list(pos = as.list(rws), command = col),
sanitize.text.function = identity)
@
\end{document}
Note: Firstly I tried to change row height at least somehow. I wanted to use add.to.row
with command
argument rep("\\[20pt]", length(rws))
, but this placed the command in front of the line and therefore did not work.
\[20pt]6 & 5.40 & 3.90 & 1.70 & 0.40 & \textit{\textit{\textit{\textit{setosa}}
So I tried to put it in the end like this: iris$Species <- paste0("\\textit{", iris$Species, "}\\[20pt]")
or iris$Species <- paste0("\\textit{", iris$Species, "}\\[20pt]\\")
, but I also did not succeed.
Edit: From the latex point of view I need to change line height inside a line such that the command will be in the very beginning of the line like this, but this does not worked me:
\begin{table}[ht]
\centering
\begin{tabular}{rrrrrl}
\hline
& Sepal.Length & Sepal.Width & Petal.Length & Petal.Width & Species \\
\hline
1 & 5.10 & 3.50 & 1.40 & 0.20 & setosa \\
\\[20pt]2 & 4.90 & 3.00 & 1.40 & 0.20 & setosa \\
3 & 4.70 & 3.20 & 1.30 & 0.20 & setosa \\
\\[20pt]4 & 4.60 & 3.10 & 1.50 & 0.20 & setosa \\
5 & 5.00 & 3.60 & 1.40 & 0.20 & setosa \\
\\[20pt]6 & 5.40 & 3.90 & 1.70 & 0.40 & setosa \\
\hline
\end{tabular}
\end{table}
\\[20pt]
--- could just be a problem of escaping? I do not know which languages is that, but in python I need"\\\\[20pt]"
(notice the four backslash). Anyway, if you post a MWE in LaTeX we could help better.