Take the 2-minute tour ×

I've been using xtable package for a long time, and looking forward to writting my first package in R... so I reckon that if I have some "cool" idea that's worth carying out, there's a great chance that somebody got there before me... =)

I'm interested in functions/packages specialized for LaTeX table creation (through R, of course). I bumped on quantreg package which has latex.table function. Any suggestion for similar function(s)/package(s)?

P.S. I'm thinking about building a webapp in which users can define their own presets/templates of tables, choose style, statistics, etc. It's an early thought, though... =)

share|improve this question
See also the related community wiki stackoverflow.com/questions/5465314/… –  Joris Meys Nov 3 '11 at 13:18
add comment

4 Answers

up vote 5 down vote accepted

I sometimes divide the task of creating LaTeX tables into two parts:

  1. I'll write the table environment, caption, and tabular environment commands directly in my LaTeX document.
  2. I'll export just the body of the table from R using a custom function.

The R export part involves several steps: Starting with a matrix of the whole table including any headings:

  1. Add any LaTeX specific formatting to the table. E.g., enclose digits in dollar symbols to ensure that negative numbers display correctly.
  2. Collapse rows into a single character value by replacing separate columns with the ampersand (&) and adding ends-of-row symbols "\\"
  3. Add any horizontal lines to be displayed in the table. I use the booktabs LaTeX package.
  4. Export the resulting character vector using the write function

The exported text file is then imported using the input command in LaTeX. I ensure that the file name corresponds to the table label.

I have used this approach in the context of writing journal articles. In these cases, there are a lot of different types of tables (e.g., multi-page tables, landscape tables, tables requiring extended margins, tables requiring particular alignment, tables where I want to change the wording of the table title). In this setting, I've mostly found it easier to just export the data from R. In this way, the result is reproducible research, but it is easier to tweak aspects of table design in the LaTeX document. And in the context of journal articles, there are usually not too many tables and rather specific formatting requirements.

However, I imagine if I were producing large numbers of batch reports, I'd consider exporting more aspects directly from R.

share|improve this answer
Neat approach, I must admit... Especially 'cause it's reproducible. Though my question was refering to "package", this is by far the most efficient way to handle complex tables in LaTeX. Thanks! –  aL3xa Jun 6 '10 at 15:36
add comment

Beyond xtable and Hmisc as listed by Rob, there are also at least

  • apsrtable which formats latex tables from one or more model objects
  • p2lh which exports R to LaTeX and HTML
  • RcmdrPlugin.Export which graphically exports output to LaTeX or HTML
  • reporttools which generates LaTeX tables of descriptive statistics

This was just based on a quick search. So there may be more for you to look at before you try to hook it into a webapp. Good luck.

share|improve this answer
Thanks! I've seen those in CRAN packages, reporttools is great find! –  aL3xa Jun 5 '10 at 15:09
Just to add to your list: estout - formats models like aprstable, based on stata estout memisc - like hmisc in some ways, also has aprstable like capabilities –  Robert Jun 6 '10 at 4:35
@Dirk thanks for the resorces –  Tyler Rinker Nov 17 '11 at 16:47
add comment

In addition to the packages mentioned above, there is the stargazer package. It works well with objects from many commonly used functions and packages (lm, glm, svyglm, plm, survival, AER, pscl, and others), as well as with zelig objects.

share|improve this answer
add comment

Apart from xtable, there's the latex function in the Hmisc package.

share|improve this answer
add comment

Your Answer


