当type ="latex"时,如何将观星台向左对齐? [英] how to align stargazer table to the left when type="latex"?

查看:94
本文介绍了当type ="latex"时,如何将观星台向左对齐?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在自动rmarkdown pdf文档中使用stargazer软件包来制作漂亮的表格.缺省情况下,Stargazer将其表放置在页面的中央.我如何让观星者生成将表格向左对齐的乳胶代码?

I use stargazer package in my automated rmarkdown pdf documents to make nice looking tables. Stargazer places its tables in the center of the page, by default. How can I let stargazer generate latex code that aligns the table to the left?

这是我的意思的示例:

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.我该如何更改而不必更改乳胶代码本身?

Note the \centering. How can I change that without having to alter the latex code itself?

推荐答案

它会显示\centering)删除\centering.

It would appear \centering is hard coded into the function. What you could do is delete \centering using sub (e.g. sub(" \\\\centering", "", out)).

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

Here's the chunk I used. I used capture.output to prevent stargazer to output what I consider intermediate result.

<<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)
@

这篇关于当type ="latex"时,如何将观星台向左对齐?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆