Reputation: 95
I am new to LaTeX, Knitr and xtable. Specifically, when constructing a table and then printing it with the xtable package, how can I:
Thank you for all your time and consideration. I have read into the Hmisc package, but don't really understand if it can help me with these problems.
Edit:
The R code chunk that I am working with looks like this.
<<echo=FALSE,results='asis'>>
thirdTable <- table.CalendarReturns(port_returns, digits=2)
tli.table <- xtable(thirdTable, align="rccccccccccccc")
print(tli.table, floating = FALSE, size="\\tiny", scalebox=1.57)
@
To clarify my problem, I would like to be able to format within that R chunk, so that my LaTeX output includes a bolded last column (including header) and negative values replaced with "()" instead of "-".
Upvotes: 1
Views: 2165
Reputation: 1
You can change each column entry to be labeled bold individually.
thirdTable[,ncol(thirdTable)] = paste0('\\textbf{',thirdTable[,ncol(thirdTable)],'}')
Upvotes: 0
Reputation: 263479
Using the output of the first example in the ?xtable help page, add a format to the column specification. The{\bfseries}
needs to have a leading >
:
\documentclass{article}
\usepackage{booktabs,dcolumn}
\begin{document}
% latex table generated in R 3.0.2 by xtable 1.7-1 package
% Tue Oct 29 18:22:49 2013
% latex table generated in R 3.0.2 by xtable 1.7-1 package
% Tue Oct 29 18:22:49 2013
\begin{table}[ht]
\centering
\begin{tabular}{rrl>{\bfseries}llr}
% Edit above line
\hline
& grade & sex & disadvg & ethnicty & tlimth \\
\hline
1 & 6 & M & YES & HISPANIC & 43 \\
2 & 7 & M & NO & BLACK & 88 \\
3 & 5 & F & YES & HISPANIC & 34 \\
4 & 3 & M & YES & HISPANIC & 65 \\
5 & 8 & M & YES & WHITE & 75 \\
6 & 5 & M & NO & BLACK & 74 \\
7 & 8 & F & YES & HISPANIC & 72 \\
8 & 4 & M & YES & BLACK & 79 \\
9 & 6 & M & NO & WHITE & 88 \\
10 & 7 & M & YES & HISPANIC & 87 \\
11 & 3 & M & NO & WHITE & 79 \\
12 & 6 & F & NO & WHITE & 84 \\
13 & 8 & M & NO & WHITE & 90 \\
14 & 5 & M & NO & WHITE & 73 \\
15 & 8 & F & NO & WHITE & 72 \\
16 & 6 & F & NO & BLACK & 82 \\
17 & 4 & M & NO & WHITE & 69 \\
18 & 3 & F & YES & HISPANIC & 17 \\
19 & 3 & M & NO & HISPANIC & 37 \\
20 & 5 & M & NO & WHITE & 70 \\
\hline
\end{tabular}
\end{table}
\end{document}
It's possible that you need to have a \usepackage{array}
, but this code seems to be succeeding for me in Texshop.app.
Upvotes: 0