Learn R Programming

lazyWeave (version 2.1.3)

lazy.table: Tables in LaTeX

Description

Generate code for custom LaTeX tables

Usage

lazy.table(x, align = "center", justify="center", placement="!H", 
  cspan = 1, cborder = NULL, cwidth = NULL, 
  rborder = NULL, rbspan = NULL, rheight = NULL, 
  rcol = NULL, usecol = "lightgray", 
  caption = NULL, footnote = NULL, textsize="\\normalsize",
  counter, counterSet=NULL, label=NULL, 
  open = TRUE, close = TRUE, translate=TRUE)

Arguments

x
Matrix to be put into the table. Other objects are coerced to matrices. Vectors are coerced to a row vector.
align
Character vector or string giving the alignment for each column. Options are "left", "center", "right".
justify
Character string giving the alignment for the table on the page. Options are "left", "center", "right".
placement
Controls the placement of the figure. Options are "ht", "t", "b", "p", "H" and can be supplemented with "!". See "Details" for more explanation.
cspan
A vector specifying how many columns of the table each column of x should span. This is used when using successive calls to latex.table to build tables with complex headers.
cborder
A vector denoting vertical border positions. Borders are placed to the right of the given columns. See "Details".
cwidth
Currently not in use. Will be used to specify the width of each column.
rborder
A vector denoting horizontal border positions. Borders are placed at the bottom of the given rows. See "Details".
rbspan
A vector or list giving the start and stop positions of the horizontal borders. Use a list when borders should go from columns 1 - 3 and 5 - 7, but not at column 4.
rheight
Currently not in use. Will be used to specify the width of each row.
rcol
A vector denoting which rows should be colored.
usecol
A character vector or string giving the color to be used for the rows in rcol. The color must be a recognized LaTeX color.
caption
Caption for the table. Currently, captions are placed above tables.
footnote
Additional footnotes to be placed below tables.
textsize
A character string giving the text size for the table. This must be valid LaTeX code. Remember to use two backslashes.
counter
The name of the counter to be used for this table
counterSet
The value to which counter should be set. In other words, the number of this table.
label
The label to be used by lazy.ref.
open
Logical. Indicates if a new table environment should be opened.
close
Logical. Indicates if the current table environment should be closed.
translate
Toggles if inputs in x should be passed through latexTranslate. This should be set to FALSE if writing custom code.

Details

cborder (or column border) will create vertical borders in the table. Borders are placed on the right side of the specified columns. If a border is needed on the far left side of the table, use 0. rborder (or row border) acts similarly, but for rows. Borders are placed under the specified rows. Use 0 if a line is needed at the top of a table. Multiple calls to latex.table may be used to make complex tables. For instance, a header may be desired with group names that span over three summary values (See example 2). In these instances, it is the responsibility of the user to make sure the number of columns in each call is the same as in the other calls. There is no way in lazyWeave to check the column consistency of tables. placement options are used as follows: ll{ ht Place the float here, i.e., approximately at the same point it occurs t Position at the top of the page b Position at the bottom of the page p Put on a special page for floats only H Places the float at precisely the location in the LaTeX code. Requires the float package } The "!" may be used after any of these in order to override LaTeX float rules and force your selection. More can be learned by reading about floats in a LaTeX manual.

Examples

Run this code
#*** Example 1: Simple Table
tab.text <- lazy.table(mtcars[, c(1, 2, 4, 6)], align="right", 
    cborder=c(0, 4), rborder=c(0, nrow(mtcars)))
    
lazy.write(
  lazy.file.start(),
  tab.text,
  lazy.file.end(),
  OutFile="Example 1.tex")
  
unlink("Example 1.tex")
  
#*** Example 2: Complex Table
person <- c("Rachel", "John", "Elizabeth", "George", "Ryan")
veg <- c("", "x", "x", "", "x")
meat <- c("x", "", "", "x", "")
soup <- c("x", "", "x", "x", "")
salad <- c("", "x", "", "", "x")
ice <- c("", "x", "x", "x", "")
cake <- c("x", "", "", "", "x")

dinner <- cbind(person, veg, meat, soup, salad, ice, cake)
colnames(dinner) <- c("Name", "Vegetarian", "Meat", 
    "Soup", "Salad", "Ice Cream", "Cake")
                      
tab1 <- lazy.table(c("", "Entree", "Side", "Dessert"), 
    cspan=c(1, 2, 2, 2),
    rborder=c(0, 0, 1), rbspan=2:7, 
    caption="Dinner Orders", close=FALSE)
tab2 <- lazy.table(colnames(dinner), 
    align=c("left", rep("center", 6)),
    cborder=c(3, 5),
    open=FALSE, close=FALSE)
tab3 <- lazy.table(dinner, 
    align=c("left", rep("center", 6)),
    cborder=c(1, 3, 5),
    rborder=c(0, nrow(dinner)), open=FALSE)
                    
lazy.write(
  lazy.file.start(),
  tab1, tab2, tab3,
  lazy.file.end(),
  OutFile="Example 2.tex")
  
unlink("Example 2.tex")

Run the code above in your browser using DataLab