[R] Hmisc latex: table column width

Lauri Nikkinen lauri.nikkinen at iki.fi
Mon Jul 7 10:12:03 CEST 2008


Frank Harrell gave me a hint:

http://biostat.mc.vanderbilt.edu/twiki/pub/Main/StatReport/latexFineControl.pdf

but I'm still puzzled. Now I do know how to modify e.g cell colors in
a table (see below) but I still know how to modify the width parameter
of the column. Can anyone give a helping hand?

Thanks,
Lauri

####### R code #########
DF <- data.frame(Titanic)
DF$long <- paste("This is a veeeeeeeeeeryyyyyyyyyy long line")
DF <- DF[, names(DF)[c(6,1:5)]]

library(Hmisc)
cell.format <- matrix(rep("", nrow(DF) * ncol(DF)), ncol = ncol(DF))
cell.format[which(DF$Freq > 100), ] <- "color{red}"

latex(DF,
       title="",
       caption="Titanic",
       file="",
       cellTexCmds=cell.format,
       rowname="",
       caption.loc="top",
       where="ht")
########################

> R.Version()
$platform
[1] "i386-pc-mingw32"

$arch
[1] "i386"

$os
[1] "mingw32"

$system
[1] "i386, mingw32"

$status
[1] ""

$major
[1] "2"

$minor
[1] "7.1"

$year
[1] "2008"

$month
[1] "06"

$day
[1] "23"

$`svn rev`
[1] "45970"

$language
[1] "R"

$version.string
[1] "R version 2.7.1 (2008-06-23)"



2008/7/4, Lauri Nikkinen <lauri.nikkinen at iki.fi>:
> R users,
>
> I'm trying to set a column width to one of the columns in a latex
> table (using Hsmic package, latex function). My intention is to get
>
> \begin{tabular}{lp{1.2in}llllll}\hline\hline
>
> Here's an example
>
> ####### R code #########
> DF <- data.frame(Titanic)
> DF$long <- paste("This is a veeeeeeeeeeryyyyyyyyyy long line")
> DF <- DF[, names(DF)[c(6,1:5)]]
>
> library(Hmisc)
> DF.latex <- format.df(DF, na.blank=TRUE, math.row.names=TRUE,
> math.col.names=TRUE)
> #and when I try...
> attr(DF.latex, "col.just")[1] <- "lp{1.2in}"
> #..it does not help
> latex(DF.latex,
>       title="",
>       caption="Titanic",
>       file="",
>       rowname="",
>       caption.loc="top",
>       where="ht")
>
> #I get
> #\begin{tabular}{lllllll}\hline\hline
> ######## end ###########
>
> How should I modify my code to get column width parameter into the latex table?
>
> Thanks
> Lauri
>



More information about the R-help mailing list