[R] formatting tables with long column names via package:xtable within Sweave

john.gavin@ubs.com john.gavin at ubs.com
Thu Jul 15 12:07:20 CEST 2004


Hi,

I use the excellent Sweave tools for writing documents
but was wondering how to neatly print a data.frame
with long column headings.
I cant manage to do this via package:xtable.

Typically the labels that I would like use 
for each column consist of more than one word, 
but even with just one word,
the heading is often wider than the contents of the column.
So the number of columns that fits onto a page 
is limited by the width of the column names.
I would like to spread the column names over 
two or more lines, to reduce that column's width,
but xtable doesn't seem to allow for this.

For example, the code

xtable(data.frame(
  longColumnHeading            = 1, 
  "column heading with spaces" = "b"))

produces the following latex.

% latex table generated in R 1.9.1 by xtable 1.2-2 package
% Thu Jul 15 10:36:24 2004
\begin{table}[ht]
\begin{center}
\begin{tabular}{rrl}
\hline
 & longColumnHeading & column.heading.with.spaces \\
\hline
1 & 1.00 & b \\
\hline
\end{tabular}
\end{center}
\end{table}

I would like to be able to change the line with the column headings

 & longColumHeading & column.heading.with.spaces \\

to a  mulit-line format (with narrower column widths), 
something like:

 & long    & column  \\
 & Column  & heading \\
 & Heading & with    \\
 &         & spaces  \\

What is the best way to do this or something similar?

I am on XP with R 1.9.1 (using XEmacs and ESS).

Regards,

John.

John Gavin <john.gavin at ubs.com>,
Quantitative Risk Models and Statistics,
UBS Investment Bank, 6th floor, 
100 Liverpool St., London EC2M 2RH, UK.
Phone +44 (0) 207 567 4289
Fax   +44 (0) 207 568 5352

Visit our website at http://www.ubs.com

This message contains confidential information and is intend...{{dropped}}




More information about the R-help mailing list