【发布时间】:2016-09-02 15:15:46
【问题描述】:
我是 R 和 LATEX 的新手(对不起拼写,但我不知道如何在 OS 上生成经典版本的 Latex)。无论如何,这是我的问题。
我的桌子有点长但很窄,所以我想把它们分成两半,让它们看起来像 enter image description here
乳胶会自动将 .1 添加到右半部分的标题中,例如左侧的“Industry”,而右侧的“Industry.1”,我想要的是两半的“Industry”,下面是我的数据和代码。
任何有用的建议将不胜感激。
\documentclass[11]{article}
\title{Privatization Report}
\author{JiaGao, PhD}
\usepackage{float}
\usepackage{array}
\usepackage[top = 0.5in, bottom = 0.5in, left = 1in, right = 1in]{geometry}
\begin{document}
\maketitle
INDUSTRY.DATA<-read.dta13("industrycode.dta")
DECRIB.DATA<-read.dta13("describe_V1.dta")
indu.count<-data.frame(table(DECRIB.DATA$industrycode2))
indu.count<-rename(indu.count,c(Var1 = "industrycode2"))
INDUSTRY.DATA<-merge(INDUSTRY.DATA,indu.count,by.x="industrycode2",
by.y = "industrycode2",all.x=TRUE)
na.list<-which(is.na(INDUSTRY.DATA$Freq == "NA"))
INDUSTRY.DATA$Freq<-replace(INDUSTRY.DATA$Freq, na.list,0)
INDUSTRY.DATA$Perc<-INDUSTRY.DATA$Freq/sum(INDUSTRY.DATA$Freq)
rm(na.list,indu.count)
<<echo = FALSE, results = 'asis'>>=
industryTable<-data.frame("Industry" = INDUSTRY.DATA[1:15,]$industryname,
"Freq" = INDUSTRY.DATA[1:15,]$Freq,
"Perc" = INDUSTRY.DATA[1:15,]$Perc,
"Industry" = INDUSTRY.DATA[16:30,]$industryname,
"Freq" = INDUSTRY.DATA[16:30,]$Freq,
"Perc" = INDUSTRY.DATA[16:30,]$Perc)
print(xtable(industryTable,caption = "Distribution of Privatization Across Manufacturing", label = "table:industry",align = c("c","p{4.5cm}","c","c","|p{4.5cm}","c","c"),digits = c(0,0,0,2,0,0,2)),caption.placement="top", include.rownames = FALSE)
@
\end{document}
【问题讨论】:
-
希望我的答案是您正在寻找的,但如果不是,请提供您的数据的 sn-p,以便我可以复制您正在做的事情。您可以通过粘贴
dput(INDUSTRY.DATA)的输出来做到这一点,或者,如果它真的很大,可以粘贴dput(head(INDUSTRY.DATA))。祝你好运。 -
您的解决方案非常适合我。我也想知道 xtable 或 Latex 中是否有任何方法可以自动生成这样的表格?