stargazer 左对齐 LaTeX 表格列 [英] stargazer left align LaTeX table columns

查看:42
本文介绍了stargazer 左对齐 LaTeX 表格列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

stargazer 自动在表格中居中值.如何左对齐列?

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

把这段代码放在一个.Rnw文件中,然后用knitr转换成.tex:

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

<<load, echo=FALSE, warning=FALSE, message=FALSE>>=
opts_chunk$set(eval=TRUE, echo=FALSE, warning=FALSE, message=FALSE, dpi=300)
@


documentclass[a4paper,11pt]{article}
usepackage{lipsum} % Required to insert dummy text

egin{document}
	itle{}
author{}
date{	oday}
maketitle

section{Header}

Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.

<<iris, results = "asis">>=
library(stargazer)
stargazer(iris[1:10,4:5], summary  = FALSE)
@

end{document}

这是 PDF 输出:

推荐答案

正如评论中所指出的,您可以对 stargazer 的输出进行后处理,也可以使用 xtable.我将演示这两种方法.

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. 后处理:将你的代码卡盘替换为以下两个代码块

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

<<echo=FALSE, results=hide>>=
library(stargazer)
tab <- stargazer(iris[1:10,4:5], summary  = FALSE) 
@

<<results=tex, echo=FALSE>>=
collapse <- function(st) paste(st, collapse="")
st <- gsub(collapse(rep("c", 3)), collapse(rep("l",3)), tab)
cat(st[4:24])
@

  • xtable:安装 xtable 包后,您可以将其用作您的代码夹

  • xtable: After installing the xtable package, you could use this as your code chuck

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

  • 我认为 xtable 方法可能更简单

    I think the xtable approach is probably easier though

    这篇关于stargazer 左对齐 LaTeX 表格列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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