'Align tableGrob to textGrob in grid

I'm trying to align a tableGrob to the left of the grid, so that the table will be aligned to the title. This is the code I'm using:

createTableGrob <- function(table){
# wrap
namesLegendTable <- warp_text(names(table), width = warpTextWidth)
table <- apply(table, MARGIN= c(1, 2), FUN = function(x)
  paste(strwrap(x, width = warpTextWidth),  collapse = "\n"))

# grob
tableGrob <- tableGrob(
  table,
  theme = myt,
  cols = namesLegendTable,
  rows = NULL
)

separators <- replicate(ncol(table) - 1,
                        segmentsGrob(x1 = unit(0, "npc"), gp=gpar(col = "white", lty=1)),
                        simplify=FALSE)

gtable::gtable_add_grob(tableGrob,
                        grobs = separators,
                        t = 1,
                        b = nrow(tableGrob),
                        l = seq_len(ncol(tableGrob)-1)+1)
}

tableGrob <- createTableGrob(table)
titlePwc <- textGrob(titlePwc,gp=gpar(fontsize=14, fontface=3), hjust=0, x=0.02)
g <- arrangeGrob(
    titlePwc,
    secTableGrob,
    ncol = 1
    )

This is the result: grid with text and table

I would like to adjust the table to the left so that it will be aligned with the text. Any advice will be appreciated.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source