我在 R 中生成了一个表格,我想让它适合页面,因为六列超出了页边距。字体大小设置为 10。如果可能的话,我还希望数字与小数点分隔符对齐(有些数字是负数)。任何帮助都非常感谢!
\begin{table}[!htbp]
\begin{tabular}{lllllll}
\hline \\[-1.8ex]
\cline{2-7}
\\[-1.8ex] & \multicolumn{6}{c}{filmweb\_rate} \\
\\[-1.8ex] & (1) & (2) & (3) & (4) & (5) & (6)\\
\hline \\[-1.8ex]
mean\_act\_rate & 0.088 & 0.078 & 0.089 & 0.087 & 0.074$^{***}$ & 0.066$^{*}$ \\
dir.rate & 0.106$^{***}$ & 0.094$^{***}$ & 0.108$^{***}$ & 0.107$^{***}$ & 0.111$^{***}$ & 0.107$^{***}$ \\
log(filmweb\_votes) & 0.235$^{***}$ & 0.246$^{***}$ & 0.233$^{***}$ & 0.235$^{***}$ & 0.233$^{***}$ & 0.235$^{***}$ \\
genreAdventure & 0.990 & 0.826 & 1.006 & 0.999 & 0.861$^{***}$ & 0.973$^{**}$ \\
genreAnimation & 0.294 & $-$0.013 & 0.381 & 0.325 & 0.010 & $-$0.093 \\
genreBiography & 0.950 & 0.599 & 0.999 & 0.959 & 0.949$^{***}$ & 0.913$^{***}$ \\
genreComedy & 0.488 & 0.418 & 0.515 & 0.479 & 0.573$^{***}$ & 0.523 \\
genreCrime & $-$0.684 & $-$0.409 & $-$0.736 & $-$0.703 & $-$0.934$^{***}$ & $-$0.936$^{***}$ \\
\hline \\[-1.8ex]
Observations & 796 & 796 & 796 & 796 & 796 & 796 \\
R$^{2}$ & 0.801 & 0.851 & 0.788 & 0.795 & 1.000 & 0.982 \\
Adjusted R$^{2}$ & 0.792 & 0.844 & 0.778 & 0.786 & 1.000 & 0.981 \\
Residual Std. Error (df = 759) & 0.073 & 0.002 & 0.090 & 0.033 & 1.001 & 0.434 \\
F Statistic (df = 36; 759) & 85.058$^{***}$ & 120.577$^{***}$ & 78.241$^{***}$ & 81.892$^{***}$ & 203,172.700$^{***}$ & 1,150.081$^{***}$ \\
\hline
\hline \\[-1.8ex]
\textit{Note:} & \multicolumn{6}{r}{$^{*}$p$<$0.1; $^{**}$p$<$0.05; $^{***}$p$<$0.01} \\
\end{tabular}
\end{table}
答案1
- 页面上的表格是否适合很大程度上取决于页面上的文本区域的大小(目前尚不清楚)
- 对于水平规则,我建议使用
booktabs
包中定义的规则 - 列之间距离的确定留给宏
\extracolsep
- 对于带有数字的列,最好使用包
S
中定义的列类型siunitx
- 上述一些建议已在问题下方的评论中提及
\documentclass{article}
\usepackage{geometry}
\usepackage{booktabs}
\usepackage{siunitx}
\begin{document}
\begin{table}[ht]
\sisetup{table-space-text-post={$^{***}$},
table-align-text-post=false,
table-format=-1.3
}
\setlength\tabcolsep{0pt}
\small
\begin{tabular*}{\textwidth}{@{\extracolsep{\fill}} l *{6}{S} }
\toprule
& \multicolumn{6}{c}{filmweb\_rate} \\
\cmidrule{2-7}
& {(1)} & {(2)} & {(3)} & {(4)} & {(5)} & {(6)} \\
\midrule
mean\_act\_rate
& 0.088 & 0.078 & 0.089 & 0.087 & 0.074$^{***}$ & 0.066$^{*}$ \\
dir.rate
& 0.106$^{***}$ & 0.094$^{***}$ & 0.108$^{***}$ & 0.107$^{***}$ & 0.111$^{***}$ & 0.107$^{***}$ \\
log(filmweb\_votes)
& 0.235$^{***}$ & 0.246$^{***}$ & 0.233$^{***}$ & 0.235$^{***}$ & 0.233$^{***}$ & 0.235$^{***}$ \\
genreAdventure
& 0.990 & 0.826 & 1.006 & 0.999 & 0.861$^{***}$ & 0.973$^{**}$ \\
genreAnimation
& 0.294 & -0.013 & 0.381 & 0.325 & 0.010 & -0.093 \\
genreBiography
& 0.950 & 0.599 & 0.999 & 0.959 & 0.949$^{***}$ & 0.913$^{***}$ \\
genreComedy
& 0.488 & 0.418 & 0.515 & 0.479 & 0.573$^{***}$ & 0.523 \\
genreCrime
& -0.684 & -0.409 & -0.736 & -0.703 & -0.934$^{***}$ & -0.936$^{***}$ \\
\midrule
Observations
& {796} & {796} & {796} & {796} & {796} & {796} \\
R$^{2}$
& 0.801 & 0.851 & 0.788 & 0.795 & 1.000 & 0.982 \\
Adjusted R$^{2}$
& 0.792 & 0.844 & 0.778 & 0.786 & 1.000 & 0.981 \\
Residual Std. Error (df = 759)
& 0.073 & 0.002 & 0.090 & 0.033 & 1.001 & 0.434 \\
F Statistic (df = 36; 759)
& {85.058$^{***}$} & {120.577$^{***}$} & {78.241$^{***}$}
& {81.892$^{***}$} & {203,172.700$^{***}$} & {1,150.081$^{***}$} \\
\midrule[\heavyrulewidth]
\multicolumn{7}{l}{\textit{Note:}
$^{*}$p$<$0.1; $^{**}$p$<$0.05; $^{***}$p$<$0.01}
\end{tabular*}
\end{table}
\end{document}
答案2
除了Zarko的答案之外,这里还有两种方法可以将表格挤压到标准文章类的文本宽度中而无需加载geometry
。 (红线表示边距。)
\documentclass{article}
\usepackage{siunitx}
\usepackage{booktabs}
\usepackage{calc}
%%% do not use in actual document
\usepackage{showframe}
\renewcommand*\ShowFrameColor{\color{red}}
%%%
\begin{document}
\begin{table}[htbp]
\sisetup{table-space-text-post={$^{***}$},
table-align-text-post=false,
table-format=-1.3
}
\setlength\tabcolsep{0pt}
\footnotesize
\begin{tabular*}{\textwidth}{@{\extracolsep{\fill}} >{\raggedright\arraybackslash}p{\widthof{Residual Std. Error}} *{6}{S} }
\toprule
& \multicolumn{6}{c}{filmweb\_rate} \\
\cmidrule{2-7}
& {(1)} & {(2)} & {(3)} & {(4)} & {(5)} & {(6)} \\
\midrule
mean\_act\_rate
& 0.088 & 0.078 & 0.089 & 0.087 & 0.074$^{***}$ & 0.066$^{*}$ \\
dir.rate
& 0.106$^{***}$ & 0.094$^{***}$ & 0.108$^{***}$ & 0.107$^{***}$ & 0.111$^{***}$ & 0.107$^{***}$ \\
log(filmweb\_votes)
& 0.235$^{***}$ & 0.246$^{***}$ & 0.233$^{***}$ & 0.235$^{***}$ & 0.233$^{***}$ & 0.235$^{***}$ \\
genreAdventure
& 0.990 & 0.826 & 1.006 & 0.999 & 0.861$^{***}$ & 0.973$^{**}$ \\
genreAnimation
& 0.294 & -0.013 & 0.381 & 0.325 & 0.010 & -0.093 \\
genreBiography
& 0.950 & 0.599 & 0.999 & 0.959 & 0.949$^{***}$ & 0.913$^{***}$ \\
genreComedy
& 0.488 & 0.418 & 0.515 & 0.479 & 0.573$^{***}$ & 0.523 \\
genreCrime
& -0.684 & -0.409 & -0.736 & -0.703 & -0.934$^{***}$ & -0.936$^{***}$ \\
\midrule
Observations
& {796} & {796} & {796} & {796} & {796} & {796} \\
R$^{2}$
& 0.801 & 0.851 & 0.788 & 0.795 & 1.000 & 0.982 \\
Adjusted R$^{2}$
& 0.792 & 0.844 & 0.778 & 0.786 & 1.000 & 0.981 \\
Residual Std. Error (df = 759)
& 0.073 & 0.002 & 0.090 & 0.033 & 1.001 & 0.434 \\
F Statistic \newline(df = 36; 759)
& {85.058$^{***}$} & {120.577$^{***}$} & {78.241$^{***}$}
& {81.892$^{***}$} & {203,172.700$^{***}$} & {1,150.081$^{***}$} \\
\midrule[\heavyrulewidth]
\multicolumn{7}{l}{\textit{Note:}
$^{*}$p$<$0.1; $^{**}$p$<$0.05; $^{***}$p$<$0.01}
\end{tabular*}
\end{table}
\begin{table}[htbp]
\sisetup{table-space-text-post={$^{***}$},
table-align-text-post=false,
table-format=-1.3
}
\setlength\tabcolsep{0pt}
\small
\begin{tabular*}{\textwidth}{@{\extracolsep{\fill}} >{\raggedright\arraybackslash}p{\widthof{genreAnimation}} *{6}{S} }
\toprule
& \multicolumn{6}{c}{filmweb\_rate} \\
\cmidrule{2-7}
& {(1)} & {(2)} & {(3)} & {(4)} & {(5)} & {(6)} \\
\midrule
mean\_act\_rate
& 0.088 & 0.078 & 0.089 & 0.087 & 0.074$^{***}$ & 0.066$^{*}$ \\
dir.rate
& 0.106$^{***}$ & 0.094$^{***}$ & 0.108$^{***}$ & 0.107$^{***}$ & 0.111$^{***}$ & 0.107$^{***}$ \\
log(filmweb\_ votes)
& 0.235$^{***}$ & 0.246$^{***}$ & 0.233$^{***}$ & 0.235$^{***}$ & 0.233$^{***}$ & 0.235$^{***}$ \\
genreAdventure
& 0.990 & 0.826 & 1.006 & 0.999 & 0.861$^{***}$ & 0.973$^{**}$ \\
genreAnimation
& 0.294 & -0.013 & 0.381 & 0.325 & 0.010 & -0.093 \\
genreBiography
& 0.950 & 0.599 & 0.999 & 0.959 & 0.949$^{***}$ & 0.913$^{***}$ \\
genreComedy
& 0.488 & 0.418 & 0.515 & 0.479 & 0.573$^{***}$ & 0.523 \\
genreCrime
& -0.684 & -0.409 & -0.736 & -0.703 & -0.934$^{***}$ & -0.936$^{***}$ \\
\midrule
Observations
& {796} & {796} & {796} & {796} & {796} & {796} \\
R$^{2}$
& 0.801 & 0.851 & 0.788 & 0.795 & 1.000 & 0.982 \\
Adjusted R$^{2}$
& 0.792 & 0.844 & 0.778 & 0.786 & 1.000 & 0.981 \\
Residual Std. Error \newline (df = 759)
& 0.073 & 0.002 & 0.090 & 0.033 & 1.001 & 0.434 \\
F Statistic \newline(df = 36; 759)
& {85.058$^{***}$} & {120.577$^{***}$} & {78.241$^{***}$}
& {81.892$^{***}$} & {203,172.700$^{***}$} & {1,150.081$^{***}$} \\
\midrule[\heavyrulewidth]
\multicolumn{7}{l}{\textit{Note:}
$^{*}$p$<$0.1; $^{**}$p$<$0.05; $^{***}$p$<$0.01}
\end{tabular*}
\end{table}
\end{document}