gpt4 book ai didi

r - 键入 ="latex"时如何将观星表向左对齐?

转载 作者:行者123 更新时间:2023-12-04 10:42:22 29 4
gpt4 key购买 nike

我在我的自动 rmarkdown pdf 文档中使用 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 代码本身的情况下更改它?

最佳答案

它会出现 \centeringhard coded into the function .你能做的就是删除\centering使用 sub (例如 sub(" \\\\centering", "", out) )。

这是我使用的块。我用过 capture.output防止 stargazer输出我认为的中间结果。

<<results = "asis">>=
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")

out <- capture.output(stargazer(data_object,title="table test",summary=FALSE,rownames=FALSE,type="latex",header=FALSE))
out <- sub(" \\\\centering", "", out)
cat(out)
@

enter image description here

关于r - 键入 ="latex"时如何将观星表向左对齐?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33543159/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com