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

We show in this vignette that texblocks can be transposed while keeping aesthetic attributes.

Multicolumn and multirows are mapped to the transposed positions.

Example 1

Column Header

tbl_col_header <- c('Run','Estimation',sprintf('$\\eta_%s$',1:4))%>%t()%>%as.tb()

Row Header

  tbl_rows_inner <- c(1:4,1)%>%as.tb()

  tbl_row_outer <- list(rep(510,4),511)%>%
    tb_reduce(margin = 1,merge = TRUE)

  tbl_row_header <- tbl_row_outer + tbl_rows_inner

Body

set.seed(123)

vals <- rnorm(12)%>%
  split(c(1,1,2,2,3,3,4,4,5,5,5,5))

tbl_body <- vals%>%purrr::map(.f=function(x){
    round(x,3)%>%t()
  })%>%
    tb_reduce(margin = 1)

Combine

tbl <- (tbl_col_header / (tbl_row_header + tbl_body))

Print

tbl%>%
  tabular()%>%
  texPreview::tex_preview()

Transpose

Notice that the multirow has been also mapped to the appropriate multicolumn

tbl%>%
  t()%>%
  tabular()%>%
  texPreview::tex_preview()

Example 2

Multiple merges across multiple rows/columns

Build Table

dat <- dplyr::tibble(
  Study    = c(1,1,1,1),
  Variable = c('Age','Age','Sex','Sex'),
  Category = c('$>=$ med','$<$ med','Male','Female'),
  Value    = c(300,300,345,255) 
)

header <- names(dat)%>%t()%>%as.tb()

a1 <- dat$Study%>%tb_reduce(merge = TRUE)
a2 <- dat$Variable%>%tb_reduce(merge = TRUE)

a <- a1 + a2

b <- dat[,-c(1,2)]%>%as.tb()

tab <- header/((a1 + a2) + b)
tab%>%
  tabular()%>%
  texPreview::tex_preview()
tab%>%
  t()%>%
  tabular()%>%
  texPreview::tex_preview()


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