Skip to contents

This function takes a data.frame and returns a table in LaTeX code that can be copied into any TeX document.

Usage

.as.latex.table(
  x,
  row.names = NULL,
  col.names = NULL,
  comments = TRUE,
  pos = "c",
  digits = 3,
  rm.zero = TRUE,
  select,
  split = NULL,
  tabular_only = FALSE,
  ...
)

Arguments

x

data.frame or RLum object (required)

row.names

currently unused

col.names

currently unused

comments

logical (with default): insert LaTeX comments

pos

character (with default): character of length one specifying the alignment of each column, e.g., pos = 'clr' for a three column data frame and center, left and right alignment

digits

numeric (with default): number of digits to be displayed (numeric fields)

rm.zero

logical (with default): remove columns containing only zeros, however, this might not be wanted in all cases

select

character (optional): a character vector passed to subset

split

integer (optional): an integer specifying the number of individual tables the data.frame is split into. Useful for wide tables. Currently unused.

tabular_only

logical (with default): if TRUE only the tabular but not the table environment is returned. This gives a lot of additional flexibility at hand

...

options: verbose

Value

Returns LaTeX code

Function version

0.2.0

Author

Christoph Burow, University of Cologne (Germany), Sebastian Kreutzer, Institute of Geography, Heidelberg University (Germany) , RLum Developer Team

How to cite

Burow, C., Kreutzer, S., 2025. .as.latex.table(): Create LaTeX tables from data.frames and RLum objects. Function version 0.2.0. In: Kreutzer, S., Burow, C., Dietze, M., Fuchs, M.C., Schmidt, C., Fischer, M., Friedrich, J., Mercier, N., Philippe, A., Riedesel, S., Autzen, M., Mittelstrass, D., Gray, H.J., Galharret, J., Colombo, M., Steinbuch, L., Boer, A.d., 2025. Luminescence: Comprehensive Luminescence Dating Data Analysis. R package version 1.1.0. https://r-lum.github.io/Luminescence/

Examples

 df <- data.frame(x = 1:10, y = letters[1:10])
.as.latex.table(df)
#> % add usepackage{adjustbox} to latex preamble 
#> \begin{table}[ht] 
#>   \centering 
#>   \begin{adjustbox}{max width=\textwidth} 
#>   \begin{tabular}{ cc }
#>      \hline 
#> 	\multicolumn{1}{p{2cm}}{\centering x } & 
#> 	\multicolumn{1}{p{2cm}}{\centering y }\\ 
#> \hline 
#>  1.000 & a \\ 
#>  2.000 & b \\ 
#>  3.000 & c \\ 
#>  4.000 & d \\ 
#>  5.000 & e \\ 
#>  6.000 & f \\ 
#>  7.000 & g \\ 
#>  8.000 & h \\ 
#>  9.000 & i \\ 
#> 10.000 & j \\ 
#>      \hline 
#>    \end{tabular} 
#>    \end{adjustbox} 
#> \end{table}
.as.latex.table(df, pos = "lr")
#> % add usepackage{adjustbox} to latex preamble 
#> \begin{table}[ht] 
#>   \centering 
#>   \begin{adjustbox}{max width=\textwidth} 
#>   \begin{tabular}{ lr }
#>      \hline 
#> 	\multicolumn{1}{p{2cm}}{\centering x } & 
#> 	\multicolumn{1}{p{2cm}}{\centering y }\\ 
#> \hline 
#>  1.000 & a \\ 
#>  2.000 & b \\ 
#>  3.000 & c \\ 
#>  4.000 & d \\ 
#>  5.000 & e \\ 
#>  6.000 & f \\ 
#>  7.000 & g \\ 
#>  8.000 & h \\ 
#>  9.000 & i \\ 
#> 10.000 & j \\ 
#>      \hline 
#>    \end{tabular} 
#>    \end{adjustbox} 
#> \end{table}
.as.latex.table(df, select = "y", pos = "r")
#> % add usepackage{adjustbox} to latex preamble 
#> \begin{table}[ht] 
#>   \centering 
#>   \begin{adjustbox}{max width=\textwidth} 
#>   \begin{tabular}{ r }
#>      \hline 
#> 	\multicolumn{1}{p{2cm}}{\centering y }\\ 
#> \hline 
#> a \\ 
#> b \\ 
#> c \\ 
#> d \\ 
#> e \\ 
#> f \\ 
#> g \\ 
#> h \\ 
#> i \\ 
#> j \\ 
#>      \hline 
#>    \end{tabular} 
#>    \end{adjustbox} 
#> \end{table}