簡體   English   中英

Stargazer R包裝:標題在乳膠表中的位置

[英]Stargazer R Package: Position of Title in Latex Table

我在r中使用stargazer Package來生成乳膠文檔的摘要統計信息。 但是,該函數會在表格頂部生成帶有標題(標題)的乳膠代碼。 是否有一種簡單的方法將標題放在桌子下面?

require(stargazer)
df <- data.frame(a=c(1,2,3),
                 b=c(2,3,5),
                 c=c(8,8,9))

stargazer(df,summary = TRUE, type = "latex",
          title = "summary statistic")

該函數的輸出如下:

\begin{table}[!htbp] \centering 
  \caption{summary statistic} 
  \label{} 
\begin{tabular}{@{\extracolsep{5pt}}lccccc} 
\\[-1.8ex]\hline 
\hline \\[-1.8ex] 
Statistic & \multicolumn{1}{c}{N} & \multicolumn{1}{c}{Mean} & \multicolumn{1}{c}{St. Dev.} & \multicolumn{1}{c}{Min} & \multicolumn{1}{c}{Max} \\ 
\hline \\[-1.8ex] 
a & 3 & 2.000 & 1.000 & 1 & 3 \\ 
b & 3 & 3.333 & 1.528 & 2 & 5 \\ 
c & 3 & 8.333 & 0.577 & 8 & 9 \\ 
\hline \\[-1.8ex] 
\end{tabular} 
\end{table} 

請注意,標題位於表格的頂部。 我想要的是以下內容:

\begin{table}[!htbp] \centering 
\begin{tabular}{@{\extracolsep{5pt}}lccccc} 
\\[-1.8ex]\hline 
\hline \\[-1.8ex] 
Statistic & \multicolumn{1}{c}{N} & \multicolumn{1}{c}{Mean} & \multicolumn{1}{c}{St. Dev.} & \multicolumn{1}{c}{Min} & \multicolumn{1}{c}{Max} \\ 
\hline \\[-1.8ex] 
a & 3 & 2.000 & 1.000 & 1 & 3 \\ 
b & 3 & 3.333 & 1.528 & 2 & 5 \\ 
c & 3 & 8.333 & 0.577 & 8 & 9 \\ 
\hline \\[-1.8ex] 
\end{tabular} 

  \caption{summary statistic} 
  \label{} 

\end{table} 

HTH安德烈亞斯

我想做同樣的事情,來到SO尋找答案。 由於沒有現成的答案,這是我的方法。 基本思想是編寫一個捕獲並重新創建觀stargazer輸出的函數,將標題和標簽移到底部:

caption_at_bottom <- function(expr) {
  x <- capture.output(expr)
  cap <- grep("\\\\caption", x)
  lab <- grep("\\\\label", x)
  last <- grep("\\\\end\\{table", x)
  cat(
    paste(
      c(x[-last], x[cap], x[lab], x[last])[-c(cap, lab)]
    , collapse = "\n")
  , "\n")
}

使用你的例子:

caption_at_bottom(
  stargazer(df, summary = TRUE, type = "latex", header = F,
          title = "summary statistic")
)

# \begin{table}[!htbp] \centering 
# \begin{tabular}{@{\extracolsep{5pt}}lccccc} 
# \\[-1.8ex]\hline 
# \hline \\[-1.8ex] 
# Statistic & \multicolumn{1}{c}{N} & \multicolumn{1}{c}{Mean} & \multicolumn{1}{c}{St. Dev.} & \multicolumn{1}{c}{Min} & \multicolumn{1}{c}{Max} \\ 
# \hline \\[-1.8ex] 
# a & 3 & 2.000 & 1.000 & 1 & 3 \\ 
# b & 3 & 3.333 & 1.528 & 2 & 5 \\ 
# c & 3 & 8.333 & 0.577 & 8 & 9 \\ 
# \hline \\[-1.8ex] 
# \end{tabular} 
#   \caption{summary statistic} 
#   \label{} 
# \end{table}

你想在stargazer()的調用中更改note參數

stargazer(df,summary = TRUE, type = "latex",
          title = "summary statistic",
          notes = "put your summary statistic note here"
)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM