Generate LaTeX or HTML table with R

R is a easy to learn statistical programming language. Its popularity has been increasing now-a-days. Many useful and productive packages are available in R. One of them is xtable package.
In most of the scientific publication LaTeX is extensively in use. Similarly, HTML is used though out the web. Table Generation is a bit boring and repetitive process in both of them. xtable package in R generate tables and the result of analysis into a beautiful tables for both LaTeX and HTML.

You can install the xtable package by using the install.packages command as,

Load the package as,

Lets create some LaTeX and HTML table from R using xtable command. For this, I am going to use the default datasets available in R. (To learn about datasets available in R, see the article “Using Data from different Packages”). Lets use carbon data from dataset package.
The top six observation in the dataset is,

The LaTeX table for these 6 observation is generated as,

The output will be a LaTeX code as,

A HTML table can be generated as,

The option include.rownames=F stops the row number to display.
The output results are,


  1. Use the mtcars dataset, fit a linear model with mpg as response variable and wt, disp and hp as predictor variable. Generate a LaTeX table and HTML table for the fitted model using xtable.

Leave a Reply