latexTabular: Convert a Data Frame or Matrix to a LaTeX Tabular

Description Usage Arguments Value Author(s) See Also Examples

View source: R/latexTabular.s

Description

latexTabular creates a character vector representing a matrix or data frame in a simple tabular environment.

Usage

1
2
3
4
latexTabular(x, headings=colnames(x),
             align =paste(rep('c',ncol(x)),collapse=''),
             halign=paste(rep('c',ncol(x)),collapse=''),
             helvetica=TRUE, translate=TRUE, hline=0, center=FALSE, ...)

Arguments

x

a matrix or data frame, or a vector that is automatically converted to a matrix

headings

a vector of character strings specifying column headings for latexTabular, defaulting to x's colnames. To make multi-line headers use the newline character inside elements of headings.

align

a character strings specifying column alignments for latexTabular, defaulting to paste(rep('c',ncol(x)),collapse='') to center. You may specify align='c|c' and other LaTeX tabular formatting.

halign

a character strings specifying alignment for column headings, defaulting to centered.

helvetica

set to FALSE to use default LaTeX font in latexTabular instead of helvetica.

translate

set to FALSE if column headings and table entries are already in LaTeX format, otherwise latexTabular will run them through latexTranslate

hline

set to 1 to put hline after heading, 2 to also put hlines before and after heading and at table end

center

set to TRUE to enclose the tabular in a LaTeX center environment

...

if present, x is run through format.df with those extra arguments

Value

a character string containing LaTeX markup

Author(s)

Frank E. Harrell, Jr.,
Department of Biostatistics,
Vanderbilt University,
fh@fharrell.com

See Also

latex.default, format.df

Examples

1
2
x <- matrix(1:6, nrow=2, dimnames=list(c('a','b'),c('c','d','this that')))
latexTabular(x)   # a character string with LaTeX markup

Example output

Loading required package: lattice
Loading required package: survival
Loading required package: Formula
Loading required package: ggplot2

Attaching package: 'Hmisc'

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

    format.pval, units

[1] "{\\fontfamily{phv}\\selectfont \\begin{tabular}{ccc}\nc&d&this that\\\\\n1&3&5\\\\\n2&4&6\\\\\n\\end{tabular}}"

Hmisc documentation built on Oct. 7, 2021, 9:16 a.m.