我是R和LATEX的新手(对不起拼写,但我不知道如何在OS上生成经典版本的乳胶)。无论如何,这是我的问题。
我有一个很长但很窄的桌子,所以我想把它们分成两半并使它们看起来像 enter image description here
乳胶会自动将.1添加到右半边的标题中,如左边的“Industry”,右边的“Industry.1”,我想要的是“工业”两半,下面是我的数据和代码。
任何有用的建议都将深表感谢。
\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}
答案 0 :(得分:0)
列名可以重复,只需在创建xtable
对象之后和调用print
命令之前定义它们,如下所示:
tab<-xtable(data.frame(LETTERS[1:13], LETTERS[14:26]))
tab
#\begin{table}[ht]
#\centering
#\begin{tabular}{rll}
# \hline
# & LETTERS.1.13. & LETTERS.14.26. \\
# \hline
# 1 & A & N \\
# 2 & B & O \\
# 3 & C & P \\
# 4 & D & Q \\
# 5 & E & R \\
# 6 & F & S \\
# 7 & G & T \\
# 8 & H & U \\
# 9 & I & V \\
# 10 & J & W \\
# 11 & K & X \\
# 12 & L & Y \\
# 13 & M & Z \\
# \hline
#\end{tabular}
#\end{table}
names(tab) <- c("le","le")
tab
# \begin{table}[ht]
# \centering
# \begin{tabular}{rll}
# \hline
# & le & le \\
# \hline
# 1 & A & N \\
# 2 & B & O \\
# 3 & C & P \\
# 4 & D & Q \\
# 5 & E & R \\
# 6 & F & S \\
# 7 & G & T \\
# 8 & H & U \\
# 9 & I & V \\
# 10 & J & W \\
# 11 & K & X \\
# 12 & L & Y \\
# 13 & M & Z \\
# \hline
# \end{tabular}
# \end{table}