stargazer left align LaTeX table columns

前端 未结 1 1739

stargazer automatically centres values within tables. How can I left align the columns?

Put this code in an .Rnw file and use knitr to

1条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-01 13:22

    As has been pointed out in the comments, you could either post-process the output of stargazer, or use xtable. I'll demonstrate both approaches.

    1. post-processing: Replace your code chuck with the following two code chunks

      <>=
      library(stargazer)
      tab <- stargazer(iris[1:10,4:5], summary  = FALSE) 
      @
      
      <>=
      collapse <- function(st) paste(st, collapse="")
      st <- gsub(collapse(rep("c", 3)), collapse(rep("l",3)), tab)
      cat(st[4:24])
      @
      
    2. xtable: After installing the xtable package, you could use this as your code chuck

      <>=
      library(xtable)
      print(xtable(iris[1:10,4:5], align="lll", caption=""))
      @
      

    I think the xtable approach is probably easier though

    0 讨论(0)
提交回复
热议问题