# latex.tabular: Display a tabular object using LaTeX. In tables: Formula-Driven Table Generation

## Description

This is similar to print.tabular, but it inserts the code to display the table in a LaTeX tabular environment.

## Usage

 1 2 ## S3 method for class 'tabular' latex(object, file = "", options = NULL, append = FALSE, ...) 

## Arguments

 object The tabular object. file A filename or connection to which to write the LaTeX code, or "" to write to the standard output. options A list of options to set for the duration of the call. append If TRUE, opens file for appending (if it is a filename rather than a connection). ... Settings for default formatting. See Details below.

## Details

The latex() method produces LaTeX output suitable for inclusion in a Sweave document.

## Value

The latex() method returns x invisibly, and prints the LaTeX script to the console.

table_options() and booktabs() return the previous settings.

print.tabular, table_options, latex

## Examples

 1 2 3 4 5 6 tab <- tabular( (Species + 1) ~ (n=1) + Format(digits=2)* (Sepal.Length + Sepal.Width)*(mean + sd), data=iris ) latex(tab) save <- booktabs() latex(tab) table_options(save) 

### Example output

Loading required package: Hmisc

Attaching package: 'Hmisc'

The following objects are masked from 'package:base':

format.pval, round.POSIXt, trunc.POSIXt, units

\begin{tabular}{lccccc}
\hline
&  & \multicolumn{2}{c}{Sepal.Length} & \multicolumn{2}{c}{Sepal.Width} \\
Species  & n & mean & sd & mean & \multicolumn{1}{c}{sd} \\
\hline
setosa  & $\phantom{0}50$ & $5.01$ & $0.35$ & $3.43$ & $0.38$ \\
versicolor  & $\phantom{0}50$ & $5.94$ & $0.52$ & $2.77$ & $0.31$ \\
virginica  & $\phantom{0}50$ & $6.59$ & $0.64$ & $2.97$ & $0.32$ \\
All  & $150$ & $5.84$ & $0.83$ & $3.06$ & $0.44$ \\
\hline
\end{tabular}
\begin{tabular}{lccccc}
\toprule
&  & \multicolumn{2}{c}{Sepal.Length} & \multicolumn{2}{c}{Sepal.Width} \\ \cmidrule(lr){3-4}\cmidrule(lr){5-6}
Species  & n & mean & sd & mean & \multicolumn{1}{c}{sd} \\
\midrule
setosa  & $\phantom{0}50$ & $5.01$ & $0.35$ & $3.43$ & $0.38$ \\
versicolor  & $\phantom{0}50$ & $5.94$ & $0.52$ & $2.77$ & $0.31$ \\
virginica  & $\phantom{0}50$ & $6.59$ & $0.64$ & $2.97$ & $0.32$ \\
All  & $150$ & $5.84$ & $0.83$ & $3.06$ & $0.44$ \\
\bottomrule
\end{tabular}


tables documentation built on Nov. 17, 2017, 7:50 a.m.