Vertical lines/borders in generated table is not continous (R+Latex+Sweave+xtable) -
i creating report in latex using r , sweave. table generated using xtable. following code used generate table
<<echo=false, results=tex>>= tabulatedval <- getstattablemacro(portfolio, normalizingrow) createdxtable <- xtable(tabulatedval, digits = 2) align(createdxtable) <- "l|l|c|" rws <- seq(1, nrow(tabulatedval), by=2) col <- rep("\\rowcolor{blue!10}", length(rws)) print(createdxtable, booktabs=true, add.to.row=list(pos=as.list(rws), command=col), include.rownames=false, size="\\small") @
the values generated fine vertical lines separating columns (as borders) not continuous.
i tried remove colors , seems better still has gaps between vertical lines/borders
<<echo=false, results=tex>>= tabulatedval <- getstattablemacro(portfolio, normalizingrow) createdxtable <- xtable(tabulatedval, digits = 2) align(createdxtable) <- "l|l|c|" rws <- seq(1, nrow(tabulatedval), by=2) print(createdxtable, booktabs=true, include.rownames=false, size="\\small") @
any idea how fix this
edit: providing more complete example asked
\documentclass[xcolor=table,professionalfonts,a4paper,11pt]{article} \usepackage[margin=1.0in]{geometry} \usepackage{graphicx} \usepackage{booktabs} \usepackage{multicol} \usepackage[skip=12pt]{caption} \usepackage{colortbl, xcolor} \usepackage{helvet} \usepackage[noae]{sweave} \begin{document} <<echo=false, results=tex>>= #colored table tabulatedval <- data.frame(statistics =c("annualized return (%)", "standard deviation (%)", "skewness", "kurtosis", "sharpe ratio", "maximum drawdown", "percent of losing months", "worst monthly return", "worst yearly return"), value =c(0.09, 6.77, 0.11, 3.18, 1.34, 5.20, 31.84, -4.09, -0.33)) createdxtable <- xtable(tabulatedval, digits = 2) align(createdxtable) <- "l|l|c|" rws <- seq(1, nrow(tabulatedval), by=2) col <- rep("\\rowcolor{blue!10}", length(rws)) print(createdxtable, booktabs=true, add.to.row=list(pos=as.list(rws), command=col), include.rownames=false, size="\\small") #uncolored table createdxtable <- xtable(tabulatedval, digits = 2) align(createdxtable) <- "l|l|c|" rws <- seq(1, nrow(tabulatedval), by=2) print(createdxtable, booktabs=true, include.rownames=false, size="\\small") @ \end{document}
the results same.
also adding generated tex file after running sweave
\documentclass[xcolor=table,professionalfonts,a4paper,11pt]{article} \usepackage[margin=1.0in]{geometry} \usepackage{graphicx} \usepackage{booktabs} \usepackage{multicol} \usepackage[skip=12pt]{caption} \usepackage{colortbl, xcolor} \usepackage{helvet} \usepackage[noae]{sweave} \begin{document} % latex table generated in r 3.0.1 xtable 1.7-1 package % mon apr 14 17:43:00 2014 \begin{table}[ht] \centering {\small \begin{tabular}{|l|c|} \toprule statistics & value \\ \midrule annualized return (\%) & 0.09 \\ \rowcolor{blue!10}standard deviation (\%) & 6.77 \\ skewness & 0.11 \\ \rowcolor{blue!10}kurtosis & 3.18 \\ sharpe ratio & 1.34 \\ \rowcolor{blue!10}maximum drawdown & 5.20 \\ percent of losing months & 31.84 \\ \rowcolor{blue!10}worst monthly return & -4.09 \\ worst yearly return & -0.33 \\ \rowcolor{blue!10} \bottomrule \end{tabular} } \end{table}% latex table generated in r 3.0.1 xtable 1.7-1 package % mon apr 14 17:43:00 2014 \begin{table}[ht] \centering {\small \begin{tabular}{|l|c|} \toprule statistics & value \\ \midrule annualized return (\%) & 0.09 \\ standard deviation (\%) & 6.77 \\ skewness & 0.11 \\ kurtosis & 3.18 \\ sharpe ratio & 1.34 \\ maximum drawdown & 5.20 \\ percent of losing months & 31.84 \\ worst monthly return & -4.09 \\ worst yearly return & -0.33 \\ \bottomrule \end{tabular} } \end{table} \end{document}
the key here booktabs
not cooperate vertical lines. can either switch away vertical rules in tables or adopt 1 of solutions described here or here on tex se. per comments , answers on questions, consensus advice seems to avoid vertical rules entirely.
Comments
Post a Comment