簡體   English   中英

如何使 Stargazer 表格適合頁面寬度(!請不要縮放表格)

[英]How to fit Stargazer tables to the page width (! please not scale the table)

有沒有辦法通過稍微修改從 Stargazer 生成的 tex 代碼來獲取頁寬表?

從 Stargazer 生成的 Tex 代碼不會調整表格的寬度,因此它通常太長或太窄。

原始 Stargazer 代碼的一個簡短示例如下。 您可以提供適用於代碼的建議。 也就是說,如何稍微修改代碼,使表格寬度以不縮放表格的方式適合頁面寬度。

\begin{table}[!htbp] \centering 
  \caption{} 
  \label{} 
\begin{tabular}{@{\extracolsep{5pt}}lD{.}{.}{-3} } 
\\[-1.8ex]\hline 
\hline \\[-1.8ex] 
\\[-1.8ex] & \multicolumn{1}{c}{Duration Gap in 0.5M} \\ 
\hline \\[-1.8ex] 
  Constant & 8.496^{***} \\ 
  & (0.060) \\ 
  & \\ 
\hline \\[-1.8ex] 
Observations & \multicolumn{1}{c}{2,241} \\ 
R$^{2}$ & \multicolumn{1}{c}{0.820} \\ 
Adjusted R$^{2}$ & \multicolumn{1}{c}{0.820} \\ 
\hline 
\hline \\[-1.8ex] 
\end{tabular} 
\end{table} 

我找到了解決方案,例如使用 \resizebox,但表格的比例發生了變化。

使用不同包(即 tabularX)的其他解決方案似乎需要對 Stargazer 生成的代碼進行許多更改。 有沒有一種方法可以使用 Stargazer 代碼在不做很多更改的情況下獲取頁寬表?

從這里開始

library(stargazer)
linear.1 <- lm(mpg ~ cyl + disp + hp, data=mtcars)
linear.2 <- lm(mpg ~ log(cyl) + disp + hp, data=mtcars)
stargazer(linear.1, linear.2, type="latex")

% Table created by stargazer v.5.2.3 by Marek Hlavac, Social Policy Institute. E-mail: marek.hlavac at gmail.com
% Date and time: Mi, Jan 11, 2023 - 17:06:46
\begin{table}[!htbp] \centering 
  \caption{} 
  \label{} 
\begin{tabular}{@{\extracolsep{5pt}}lcc} 
\\[-1.8ex]\hline 
\hline \\[-1.8ex] 
 & \multicolumn{2}{c}{\textit{Dependent variable:}} \\ 
\cline{2-3} 
\\[-1.8ex] & \multicolumn{2}{c}{mpg} \\ 
\\[-1.8ex] & (1) & (2)\\ 
\hline \\[-1.8ex] 
 cyl & $-$1.227 &  \\ 
  & (0.797) &  \\ 
  & & \\ 
 log(cyl) &  & $-$7.833$^{*}$ \\ 
  &  & (4.136) \\ 
  & & \\ 
 disp & $-$0.019$^{*}$ & $-$0.018$^{*}$ \\ 
  & (0.010) & (0.010) \\ 
  & & \\ 
 hp & $-$0.015 & $-$0.014 \\ 
  & (0.015) & (0.014) \\ 
  & & \\ 
 Constant & 34.185$^{***}$ & 40.165$^{***}$ \\ 
  & (2.591) & (5.139) \\ 
  & & \\ 
\hline \\[-1.8ex] 
Observations & 32 & 32 \\ 
R$^{2}$ & 0.768 & 0.777 \\ 
Adjusted R$^{2}$ & 0.743 & 0.753 \\ 
Residual Std. Error (df = 28) & 3.055 & 2.996 \\ 
F Statistic (df = 3; 28) & 30.877$^{***}$ & 32.488$^{***}$ \\ 
\hline 
\hline \\[-1.8ex] 
\textit{Note:}  & \multicolumn{2}{r}{$^{*}$p$<$0.1; $^{**}$p$<$0.05; $^{***}$p$<$0.01} \\ 
\end{tabular} 
\end{table} 

並改變

\begin{tabular}{@{\extracolsep{5pt}} 

\begin{tabular*}{\textwidth}{c @{\extracolsep{\fill}}

請注意,您在stargazer中有一個選項可以調整列寬,我通過以下方式在 stargazer 中得到了非常相似的結果:

stargazer(linear.1, linear.2, type="latex", column.sep.width = "120pt")

暫無
暫無

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

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