knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)
library(texblocks)
library(texPreview)
tex_opts$set(returnType = 'html')
tex_opts$append(list(cleanup='tex'))

Single blocks

as.tb('$\\alpha$')
as.tb('aaa')

Replicate

rep(as.tb('$\\alpha$'),3)

List

lapply(1:3,as.tb)

Converting from different classes

data.frame

iris%>%
  head(5)%>%
  as.tb()
iris%>%
  head(5)%>%
  as.tb()%>%
  tabular()%>%
  texPreview::tex_preview()

matrix

matrix(0,3,3)%>%
  as.tb()
matrix(0,3,3)%>%
  as.tb()%>%
  tabular()%>%
  texPreview::tex_preview()

sparse matrix

Matrix::bdiag(Matrix::Diagonal(2), matrix(1:3, 3,4), diag(3:2))%>%
  as.tb()
Matrix::bdiag(Matrix::Diagonal(2), matrix(1:3, 3,4), diag(3:2))%>%
  as.tb()%>%
  tabular()%>%
  texPreview::tex_preview()

Converting to different classes

as.data.frame

matrix(1:9,3,3)%>%
  as.tb()%>%
  as.data.frame()

Combining blocks

Horizontal

x <- as.tb('$\\alpha$')
y <- as.tb('aaa')
z <- as.tb('$\\beta$')

x1 <- x+y+z
x1%>%
  tabular()%>%
  texPreview::tex_preview()

Vertical

x/y/z
(x/y/z)%>%
  tabular()%>%
  texPreview::tex_preview()

Combined texblocks are texblocks themselves, thus can be further combined.

x2 <- x1 / x1 # 2x3 object
x2 + x2
(x2 + x2)%>%
  tabular()%>%
  texPreview::tex_preview()

Unequal blocks

x3 <- x2/x2 # 4x3 object

# 4x6 object with empty block in the lower right hand side of the table
x2 + x3
(x2 + x3)%>%
  tabular()%>%
  texPreview::tex_preview()

Creating a tabular object

# default alignment
x1%>%
  texblocks::tabular()%>%
  texPreview::tex_preview()
# manual alignment
x1%>%
  texblocks::tabular(align = '|cc|c')%>%
  texPreview::tex_preview()


metrumresearchgroup/texblocks documentation built on July 18, 2020, 1:45 a.m.