我在自动化的rmarkdown pdf文档中使用stargazer包来制作漂亮的表格。默认情况下,stargazer会将其表格放置在页面中央。我该如何让stargazer生成latex代码,将表格对齐到左边?
以下是一个示例:
library(stargazer)
data_object <- structure(list(test = structure(c(1L, 1L, 2L, 2L), .Label = c("test1", "test2"), class = "factor"), test2 = structure(1:4, .Label = c("1", "2", "3", "4"), class = "factor")), .Names = c("test", "test2"), row.names = c(NA, -4L), class = "data.frame")
stargazer(data_object,title="table test",summary=FALSE,rownames=FALSE,type="latex",header=FALSE)
它生成的代码是:
\begin{table}[!htbp] \centering
\caption{table test}
\label{}
\begin{tabular}{@{\extracolsep{5pt}} cc}
\\[-1.8ex]\hline
\hline \\[-1.8ex]
test & test2 \\
\hline \\[-1.8ex]
test1 & 1 \\
test1 & 2 \\
test2 & 3 \\
test2 & 4 \\
\hline \\[-1.8ex]
\end{tabular}
\end{table}
请注意
\centering
。我如何在不更改LaTeX代码本身的情况下更改它?
sub(" \\\\centering", "",stargazer(data_object,title="table test",summary=FALSE,rownames=FALSE,type="latex",header=FALSE))
?但是似乎并没有起作用。 - rdatasculptor