latexTablePDF: Renders a LaTeX table as a PDF file.

View source: R/latexTablePDF.R

latexTablePDFR Documentation

Renders a LaTeX table as a PDF file.

Description

latexTablePDF() takes an object produced by \linkIntlatexTable and writes a PDF file. It can also write the corresponding .tex file.

Usage

latexTablePDF(
  latexTable,
  container = TRUE,
  containerFilename = "tableContainer.tex",
  outputFilenameStem = "latexTable",
  writePDF = TRUE,
  writeTex = FALSE,
  overwriteExisting = FALSE,
  verbose = FALSE,
  continuedFloat = FALSE,
  continuedFloatStar = FALSE,
  firstPageEmpty = container,
  firstTableNumber = NULL,
  openPDFOnExit = TRUE
)

Arguments

latexTable

Object of class latexTable (typically produced by latexTable()) or a list of such objects.

container

Logical variable. Should the LaTeX code in latexTable be inserted into a LaTeX file that contains a complete LaTeX preamble and the \begin{document} and \end{document} tags? If you want latexTablePDF to produce a PDF file, container must be TRUE. But if you just want to write latexTable to disk as a .tex file that you will insert into your own larger LaTeX document, container should probably be FALSE.

containerFilename

A string. Specifies the path of the "container" LaTeX file into which the latexTable table or tables will be inserted to make a complete LaTeX file that can be rendered as PDF. By default, it is "tableContainer.tex", which is included in this package.

outputFilenameStem

A string. It is the path and name of the file is to be saved to disk, up to the extension. For example, if you want to save "myTable.pdf" to disk, set outputFilenameStem = "mytable".

writePDF

Logical variable. Should a PDF file be saved to disk?

writeTex

Logical variable. Should a .tex file be saved to disk?

overwriteExisting

Logical variable. Should files to be saved overwrite existing files that have the same names?

verbose

Logical variable. latexTablePDF calls pdflatex to render PDF files, and if verbose is TRUE, all of the output from pdflatex will be printed to screen. Useful for debugging.



continuedFloat

Logical variable. Should be TRUE if the table or tables to be rendered are part of a series and should all share the same number. For example, continuedFloat should be true if latexTable is a list of tables and you all want them to be numbered as Table\NB3.

continuedFloatStar

Logical variable. Should be TRUE if the table or tables to be rendered are part of a series, and if all tables should share the same number but be distinguished by some secondary character. For example, continuedFloatStar should be true if latexTable is a list of tables and you all want them to be numbered as Table\NB3a, Table\NB3b, etc.
\indent continuedFloat and continuedFloatStar cannot both be TRUE.

firstPageEmpty

Logical variable. Defaults to the value of container. If TRUE, the page that contains the first table in latexTable will have an empty header and footer. (Technically, latexTablePDF will insert \thispagestyle{empty} into the code block that contains the first table in latexTable.)

firstTableNumber

Integer. What number should the first table in latexTable have?
\indent By default, the table numbering will be "natural." That is, the number of the first latexTable table will be determined by the number of preceding tables in the document. For example, if you use latexTablePDF() to create a .tex file that you then insert into a larger LaTeX document, and if the .tex file is preceded in the LaTeX document by two tables, the first table created by latexTable() will be Table\NB3.



openPDFOnExit

Logical variable. Open the PDF file after it is created by latexTablePDF? This argument has an effect only on Windows, and only if writePDF is TRUE.

Details

Although latexTablePDF produces PDF files by default, it is also useful for creating .tex files. For example, you may have a list of tables produced by latexTable() and a complex LaTeX document that contains many different sections and tables. When latexTablePDF is used with writeTex = TRUE, it will produce a single file that contains LaTeX code for all of the tables in your list. You can then insert those tables into your LaTeX document by adding a single \input or \include command to your LaTeX document. For details, see vignette("tables", package = "Bullock").

Note

Required LaTeX tools. If writePDF is FALSE, you do not need to have LaTeX installed. But if writePDF is TRUE:

  • pdflatex must be installed on your system. It is part of almost every LaTeX installation. The array and afterpage packages must also be installed; if you have a LaTeX installation, you already have these packages.

  • The booktabs, caption, and numprint must be installed.

  • If containerFilename is "tableContainer.tex" (the default), the fancyhdr, footmisc, geometry, and ragged2e packages must be installed.

  • If you are producing a landscaped table, the pdflscape package must be installed.

  • If your latexTable() output was produced with floatPlacement = 'H', the float package must be installed.

See Also

Other functions for making tables: \linkIntlatexTable, \linkIntregTable. See also the Building better tables in less time and Using latexTable() with R Markdown and Rnw documents vignettes.

Examples

## Not run: 
  data(iris)
  lm1 <- lm(Sepal.Length ~ Petal.Length,               data = iris)
  lm2 <- lm(Sepal.Length ~ Petal.Length + Petal.Width, data = iris)
  lm3 <- lm(Sepal.Length ~ Petal.Length * Petal.Width, data = iris)
  lmList <- list(lm1, lm2, lm3)
  rT1 <- regTable(lmList)
  lT1 <- latexTable(
    mat        = rT1,
    colNames   = lt_colNumbers(),
    rowNames   = c(
      "Intercept", 
      "Petal length", 
      "Petal width", 
      "Petal length $\\times$ petal width"),
    footerRows = list(lt_nobsRow(), lt_rSquaredRow()),
    spacerRows = 1,  # insert white space between Intercept row and other rows
    caption    = paste0(
      "\\textit{Sepal length as a function of petal length and petal width.} ",
      "Entries are estimates and standard errors from OLS regressions..."
    )
  )
  latexTablePDF(lT1, outputFilenameStem = "irisData")


  # Create a PDF or .tex file that contains two tables:
  lm1v <- update(lm1, subset = (Species == 'versicolor'))
  lm2v <- update(lm2, subset = (Species == 'versicolor'))
  lm3v <- update(lm3, subset = (Species == 'versicolor'))
  rT2  <- regTable(list(lm1v, lm2v, lm3v))
  lT2  <- update(lT1, mat = rT2, commandName = "tableVersicolor")

  latexTablePDF(                                # PDF with two pages
    lT2, 
    outputFilenameStem = "irisData_twoTables")  
  latexTablePDF(                                # add .tex file with code for two tables
    lT2, 
    outputFilenameStem = "irisData_twoTables",
    writeTex           = TRUE)

## End(Not run)  

jbullock35/Bullock documentation built on April 1, 2022, 6:21 p.m.