简体   繁体   English

stargazer左对齐LaTeX表列

[英]stargazer left align LaTeX table columns

stargazer automatically centres values within tables. stargazer自动将值放在表格中。 How can I left align the columns? 如何左列对齐?

Put this code in an .Rnw file and use knitr to convert to .tex: 将此代码放在.Rnw文件中并使用knitr转换为.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

\begin{document}
\title{}
\author{}
\date{\today}
\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}

This is the PDF output: 这是PDF输出:

在此输入图像描述

As has been pointed out in the comments, you could either post-process the output of stargazer, or use xtable. 正如评论中指出的那样,您可以对stargazer的输出进行后处理,也可以使用xtable。 I'll demonstrate both approaches. 我将演示这两种方法。

  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]) @ 
  2. xtable : After installing the xtable package, you could use this as your code chuck xtable :安装xtable包之后,你可以使用它作为代码夹头

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

I think the xtable approach is probably easier though 我认为xtable方法可能更容易

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM