Stargazer 帮忙摆放长桌

Stargazer 帮忙摆放长桌

我用 Stargazer 在 R 中制作了一个表格,但它太大了,无法在 LyX 中放入一页。我试过使用 \longtable,但似乎不起作用(可能是做错了)。这是原始代码

\begin{table}[!htbp] \centering 
  \caption{Modellerne} 
  \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}{lprice} \\ 
\\[-1.8ex] & (1) & (2)\\ 
\hline \\[-1.8ex] 
 larea & 0.911$^{***}$ & 0.956$^{***}$ \\ 
  & (0.011) & (0.007) \\ 
  bathrooms & 0.059$^{***}$ & 0.060$^{***}$ \\ 
  & (0.009) & (0.009) \\ 
  floor & 0.020$^{***}$ & 0.020$^{***}$ \\ 
  & (0.001) & (0.001) \\ 
  rebuild00 & 0.062$^{***}$ & 0.067$^{***}$ \\ 
  & (0.011) & (0.011) \\ 
  roof\_cemen & $-$0.107$^{***}$ & $-$0.118$^{***}$ \\ 
  & (0.020) & (0.020) \\ 
  roof\_fiber & $-$0.068$^{***}$ & $-$0.075$^{***}$ \\ 
  & (0.009) & (0.008) \\ 
  roof\_board & $-$0.079$^{***}$ & $-$0.085$^{***}$ \\ 
  & (0.009) & (0.009) \\ 
  roof\_flat & $-$0.099$^{***}$ & $-$0.108$^{***}$ \\ 
  & (0.009) & (0.009) \\ 
  roof\_tile & $-$0.075$^{***}$ & $-$0.076$^{***}$ \\ 
  & (0.009) & (0.009) \\ 
  in1 & $-$0.031 & $-$0.038 \\ 
  & (0.035) & (0.035) \\ 
  in2 & $-$0.025$^{**}$ & $-$0.022$^{**}$ \\ 
  & (0.010) & (0.010) \\ 
  in3 & $-$0.038$^{***}$ & $-$0.035$^{***}$ \\ 
  & (0.007) & (0.007) \\ 
  in4 & $-$0.011$^{**}$ & $-$0.011$^{**}$ \\ 
  & (0.005) & (0.005) \\ 
  big\_roadsCon & $-$1.595$^{***}$ & $-$1.763$^{***}$ \\ 
  & (0.170) & (0.170) \\ 
  lrailways & 0.036$^{***}$ & 0.032$^{***}$ \\ 
  & (0.003) & (0.003) \\ 
  allgoods & 0.00004$^{***}$ & 0.0001$^{***}$ \\ 
  & (0.00001) & (0.00001) \\ 
  rental & $-$0.00004$^{***}$ & $-$0.0001$^{***}$ \\ 
  & (0.00000) & (0.00000) \\ 
  lIncome & 0.081$^{***}$ & 0.075$^{***}$ \\ 
  & (0.010) & (0.008) \\ 
  EducShort & $-$0.104$^{***}$ & $-$0.100$^{***}$ \\ 
  & (0.014) & (0.014) \\ 
  EducMed & $-$0.032$^{***}$ & $-$0.031$^{***}$ \\ 
  & (0.005) & (0.004) \\ 
  Wealth & $-$0.001$^{***}$ &  \\ 
  & (0.0002) &  \\ 
  Single & $-$0.013$^{**}$ &  \\ 
  & (0.006) &  \\ 
  shopservice & 0.003$^{***}$ &  \\ 
  & (0.0004) &  \\ 
  residents & $-$0.00000$^{***}$ &  \\ 
  & (0.00000) &  \\ 
  rooms & 0.016$^{***}$ &  \\ 
  & (0.003) &  \\ 
  Constant & 10.165$^{***}$ & 10.112$^{***}$ \\ 
  & (0.047) & (0.034) \\ 
 \hline \\[-1.8ex] 
Observations & 8,880 & 8,880 \\ 
R$^{2}$ & 0.809 & 0.806 \\ 
Adjusted R$^{2}$ & 0.809 & 0.805 \\ 
Residual Std. Error & 0.189 (df = 8854) & 0.190 (df = 8859) \\ 
F Statistic & 1,501.224$^{***}$ (df = 25; 8854) & 1,837.336$^{***}$ (df 
= 20; 8859) \\ 
\hline 
\hline \\[-1.8ex] 
\textit{Note:}  & \multicolumn{2}{r}{$^{*}$p$<$0.1; $^{**}$p$<$0.05; 
$^{***}$p$<$0.01} \\ 
\end{tabular} 
\end{table} 

有人知道如何让表格适合两页吗?谢谢

答案1

环境table不能跨页面拆分。删除\begin{table}\centering\end{table},替换tabularlongtable,将\caption和 标记移动到 之后\begin{longtable}{..}。当然,还要添加\usepackage{longtable}到前言中。

在此处输入图片描述

\documentclass{article}
\usepackage{longtable}

\begin{document}

\begin{longtable}{@{\extracolsep{5pt}}lcc} 
 \caption{Modellerne \label{foo}}   \\
\\[-1.8ex]\hline 
\hline \\[-1.8ex] 
 & \multicolumn{2}{c}{\textit{Dependent variable:}} \\ 
\cline{2-3} 
\\[-1.8ex] & \multicolumn{2}{c}{lprice} \\ 
\\[-1.8ex] & (1) & (2)\\ 
\hline \\[-1.8ex] 
 larea & 0.911$^{***}$ & 0.956$^{***}$ \\ 
  & (0.011) & (0.007) \\ 
  bathrooms & 0.059$^{***}$ & 0.060$^{***}$ \\ 
  & (0.009) & (0.009) \\ 
  floor & 0.020$^{***}$ & 0.020$^{***}$ \\ 
  & (0.001) & (0.001) \\ 
  rebuild00 & 0.062$^{***}$ & 0.067$^{***}$ \\ 
  & (0.011) & (0.011) \\ 
  roof\_cemen & $-$0.107$^{***}$ & $-$0.118$^{***}$ \\ 
  & (0.020) & (0.020) \\ 
  roof\_fiber & $-$0.068$^{***}$ & $-$0.075$^{***}$ \\ 
  & (0.009) & (0.008) \\ 
  roof\_board & $-$0.079$^{***}$ & $-$0.085$^{***}$ \\ 
  & (0.009) & (0.009) \\ 
  roof\_flat & $-$0.099$^{***}$ & $-$0.108$^{***}$ \\ 
  & (0.009) & (0.009) \\ 
  roof\_tile & $-$0.075$^{***}$ & $-$0.076$^{***}$ \\ 
  & (0.009) & (0.009) \\ 
  in1 & $-$0.031 & $-$0.038 \\ 
  & (0.035) & (0.035) \\ 
  in2 & $-$0.025$^{**}$ & $-$0.022$^{**}$ \\ 
  & (0.010) & (0.010) \\ 
  in3 & $-$0.038$^{***}$ & $-$0.035$^{***}$ \\ 
  & (0.007) & (0.007) \\ 
  in4 & $-$0.011$^{**}$ & $-$0.011$^{**}$ \\ 
  & (0.005) & (0.005) \\ 
  big\_roadsCon & $-$1.595$^{***}$ & $-$1.763$^{***}$ \\ 
  & (0.170) & (0.170) \\ 
  lrailways & 0.036$^{***}$ & 0.032$^{***}$ \\ 
  & (0.003) & (0.003) \\ 
  allgoods & 0.00004$^{***}$ & 0.0001$^{***}$ \\ 
  & (0.00001) & (0.00001) \\ 
  rental & $-$0.00004$^{***}$ & $-$0.0001$^{***}$ \\ 
  & (0.00000) & (0.00000) \\ 
  lIncome & 0.081$^{***}$ & 0.075$^{***}$ \\ 
  & (0.010) & (0.008) \\ 
  EducShort & $-$0.104$^{***}$ & $-$0.100$^{***}$ \\ 
  & (0.014) & (0.014) \\ 
  EducMed & $-$0.032$^{***}$ & $-$0.031$^{***}$ \\ 
  & (0.005) & (0.004) \\ 
  Wealth & $-$0.001$^{***}$ &  \\ 
  & (0.0002) &  \\ 
  Single & $-$0.013$^{**}$ &  \\ 
  & (0.006) &  \\ 
  shopservice & 0.003$^{***}$ &  \\ 
  & (0.0004) &  \\ 
  residents & $-$0.00000$^{***}$ &  \\ 
  & (0.00000) &  \\ 
  rooms & 0.016$^{***}$ &  \\ 
  & (0.003) &  \\ 
  Constant & 10.165$^{***}$ & 10.112$^{***}$ \\ 
  & (0.047) & (0.034) \\ 
 \hline \\[-1.8ex] 
Observations & 8,880 & 8,880 \\ 
R$^{2}$ & 0.809 & 0.806 \\ 
Adjusted R$^{2}$ & 0.809 & 0.805 \\ 
Residual Std. Error & 0.189 (df = 8854) & 0.190 (df = 8859) \\ 
F Statistic & 1,501.224$^{***}$ (df = 25; 8854) & 1,837.336$^{***}$ (df 
= 20; 8859) \\ 
\hline 
\hline \\[-1.8ex] 
\textit{Note:}  & \multicolumn{2}{r}{$^{*}$p$<$0.1; $^{**}$p$<$0.05; 
$^{***}$p$<$0.01} \\ 
\end{longtable} 

\end{document}

答案2

我根据siunitx和提出了以下改进建议booktabs

\documentclass{article}
\usepackage{longtable, booktabs}
\usepackage{siunitx}

\begin{document}

\sisetup{table-format=-1.5, table-number-alignment=center, table-space-text-pre=(, table-space-text-post=\textsuperscript{***}, table-align-text-pre=false, table-align-text-post=false}
\begin{longtable}{lSS}%@{\extracolsep{5pt}}
 \caption{Modellerne \label{foo}} \\
 \toprule\midrule
 \endfirsthead
 %
 \multicolumn{3}{c}{\tablename~\thetable: Modellerne}\\
 \midrule
 \endhead
 %
 \midrule
 \multicolumn{3}{r}{\em\footnotesize To be continued on next page}
 \endfoot
%
\midrule\bottomrule\addlinespace
 \multicolumn{3}{@{}l}{\textit{Note: } \textsuperscript{*}$\,p < 0.1$;\quad \textsuperscript{**}$\,p < 0.05$;\quad
 \textsuperscript{***}$\,p < 0.01$}.
 \endlastfoot
 & \multicolumn{2}{c}{\textit{Dependent variable:}} \\
\cmidrule{2-3}
& \multicolumn{2}{c}{lprice}\\
 & {(1)} & {(2)} \\
\midrule
 larea & 0.911 \textsuperscript{***} & 0.956 \textsuperscript{***} \\
  & {(}0.011{)} & {(}0.007{)} \\
\addlinespace
  bathrooms & 0.059 \textsuperscript{***} & 0.060 \textsuperscript{***} \\
  & {(}0.009{)} & {(}0.009{)} \\
\addlinespace
  floor & 0.020 \textsuperscript{***} & 0.020 \textsuperscript{***} \\
  & {(}0.001{)} &{ (}0.001{)} \\
\addlinespace
  rebuild00 & 0.062 \textsuperscript{***} & 0.067 \textsuperscript{***} \\
  & {(}0.011{)} & {(}0.011{)} \\
\addlinespace
  roof\_cemen & - 0.107 \textsuperscript{***} & - 0.118 \textsuperscript{***} \\
  & {(}0.020{)} &{(}0.020{)} \\
\addlinespace
 roof\_fiber & - 0.068 \textsuperscript{***} & - 0.075 \textsuperscript{***} \\
 & {(}0.009{)} & {(}0.008{)} \\
\addlinespace
 roof\_board & - 0.079 \textsuperscript{***} & - 0.085 \textsuperscript{***} \\
 & {(}0.009{)} & {(}0.009{)} \\
\addlinespace
 roof\_flat & - 0.099 \textsuperscript{***} & - 0.108 \textsuperscript{***} \\
 & {(}0.009{)} & {(}0.009{)} \\
\addlinespace
 roof\_tile & - 0.075 \textsuperscript{***} & - 0.076 \textsuperscript{***} \\
 & {(}0.009{)} & {(}0.009{)} \\
\addlinespace
 in1 & - 0.031 & - 0.038 \\
 & {(}0.035{)} & {(}0.035{)} \\
\addlinespace
 in2 & - 0.025 \textsuperscript{**} & - 0.022 \textsuperscript{**} \\
 & {(}0.010{)} & {(}0.010{)} \\
\addlinespace
 in3 & - 0.038 \textsuperscript{***} & - 0.035 \textsuperscript{***} \\
 & {(}0.007{)} & {(}0.007{)} \\
\addlinespace
 in4 & - 0.011 \textsuperscript{**} & - 0.011 \textsuperscript{**} \\
 & {(}0.005{)} & {(}0.005{)} \\
\addlinespace
 big\_roadsCon & - 1.595 \textsuperscript{***} & - 1.763 \textsuperscript{***} \\
 & {(}0.170{)} & {(}0.170{)} \\
\addlinespace
 lrailways & 0.036 \textsuperscript{***} & 0.032 \textsuperscript{***} \\
 & {(}0.003{)} & {(}0.003{)} \\
\addlinespace
 allgoods & 0.00004 \textsuperscript{***} & 0.0001 \textsuperscript{***} \\
 & {(}0.00001{)} & {(}0.00001{)} \\
\addlinespace
 rental & - 0.00004 \textsuperscript{***} & - 0.0001 \textsuperscript{***} \\
 & {(}0.00000{)} & {(}0.00000{)} \\
\addlinespace
 lIncome & 0.081 \textsuperscript{***} & 0.075 \textsuperscript{***} \\
 & {(}0.010{)} & {(}0.008{)} \\
\addlinespace
 EducShort & - 0.104 \textsuperscript{***} & - 0.100 \textsuperscript{***} \\
 & {(}0.014{)} & {(}0.014{)} \\
\addlinespace
 EducMed & - 0.032 \textsuperscript{***} & - 0.031 \textsuperscript{***} \\
 & {(}0.005{)} & {(}0.004{)} \\
\addlinespace
 Wealth & - 0.001 \textsuperscript{***} & \\
 & {(}0.0002{)} & \\
\addlinespace
 Single & - 0.013 \textsuperscript{**} & \\
 & {(}0.006{)} & \\
\addlinespace
 shopservice & 0.003 \textsuperscript{***} & \\
 & {(}0.0004{)} & \\
\addlinespace
 residents & - 0.00000 \textsuperscript{***} & \\
 & {(}0.00000{)} & \\
\addlinespace
 rooms & 0.016 \textsuperscript{***} & \\
 & {(}0.003{)} & \\
\addlinespace
 Constant & 10.165 \textsuperscript{***} & 10.112 \textsuperscript{***} \\
 & {(}0.047{)} & {(}0.034{)} \\
\addlinespace
 \hline \\
\addlinespace[-1.8ex]
Observations & 8,880 & 8,880 \\
\addlinespace
$R ^{2}$ & 0.809 & 0.806 \\
Adjusted R$^{2}$ & 0.809 & 0.805 \\
\addlinespace
Residual Std. Error & 0.189 & 0.190 \\
 & {(df = 8854)} & {(df = 8859)} \\
 \addlinespace
F Statistic & 1{,}501.224\textsuperscript{***} & 1{,}837.336\textsuperscript{***} \\
 & {(df = 25{;} 8854)} & {(df = 20; 8859)}
\end{longtable}

\end{document} 

在此处输入图片描述 在此处输入图片描述

答案3

通过使用包ltablex、、tabularxthreepartablex andsiunitx,您可以改善表格外观:

在此处输入图片描述

在此处输入图片描述

在此处输入图片描述

\documentclass{article}
\usepackage{booktabs,
            ltablex,
            threeparttablex}
\renewcommand\TPTtagStyle{\bfseries}%for formating tags (in table, in items)
\usepackage{siunitx}

\begin{document}
    \begin{ThreePartTable}
\sisetup{table-format=-1.5,
         input-symbols = {( - )},
         table-space-text-pre=(,
         table-space-text-post=\tnote{***},
         table-align-text-pre=false,
         table-align-text-post=false}
    \begin{TableNotes}[para]
\item[*]    $p < 0.1$
\item[**]   $p < 0.05$
\item[***]  $p < 0.01$
    \end{TableNotes}
%
\begin{tabularx}{0.75\linewidth}{@{} X S S @{}}
% long table headers and footers
    \caption{Modellerne}
\label{foo}                                                     \\
    \toprule
            & \multicolumn{2}{c}{\textit{Dependent variable:}}  \\
    \cmidrule(lr){2-3}
            & \multicolumn{2}{c}{lprice}                        \\
            & {(1)}             & {(2)}                         \\
    \midrule
\endfirsthead
    \caption{Modellerne (cont.)}                               \\
    \midrule
            & \multicolumn{2}{c}{\textit{Dependent variable:}}  \\
    \cmidrule(lr){2-3}
            & \multicolumn{2}{c}{lprice}                        \\
            & {(1)}             & {(2)}                         \\
    \midrule
\endhead
    \midrule
\multicolumn{3}{r}{\footnotesize\emph{continued on the next page}}
\endfoot
    \bottomrule
    \insertTableNotes
\endlastfoot
% table body
larea       & 0.911 \tnote{***} & 0.956 \tnote{***}             \\*
            & (0.011)           & (0.007)                       \\
    \addlinespace
bathrooms   & 0.059 \tnote{***} & 0.060 \tnote{***}             \\*
            & (0.009) & (0.009)                                 \\
    \addlinespace
floor       & 0.020 \tnote{***} & 0.020 \tnote{***}             \\*
            & (0.001)           & ( 0.001)                      \\
    \addlinespace
rebuild00   & 0.062 \tnote{***} & 0.067 \tnote{***}             \\*
            & (0.011)           & (0.011)                       \\
    \addlinespace
roof\_cemen & -0.107 \tnote{***}& -0.118 \tnote{***}            \\*
            & (0.020)           & (0.020)                       \\
    \addlinespace
roof\_fiber & -0.068 \tnote{***}& -0.075 \tnote{***}            \\*
            & (0.009)           & (0.008)                       \\
    \addlinespace
roof\_board & -0.079 \tnote{***}& -0.085 \tnote{***}            \\*
            & (0.009)           & (0.009)                       \\
    \addlinespace
roof\_flat  & -0.099 \tnote{***}& -0.108 \tnote{***}            \\*
            & (0.009)           & (0.009)                       \\
    \addlinespace
 roof\_tile & -0.075 \tnote{***} & -0.076 \tnote{***}           \\*
            & (0.009)                       & (0.009)           \\
    \addlinespace
in1         & -0.031            & -0.038                        \\*
            & (0.035)           & (0.035)                       \\
    \addlinespace
 in2        & -0.025 \tnote{**} & -0.022 \tnote{**}             \\*
            & (0.010)           & (0.010)                       \\
    \addlinespace
 in3        & -0.038 \tnote{***}& -0.035 \tnote{***}            \\*
            & (0.007)           & (0.007)                       \\
    \addlinespace
in4         & -0.011 \tnote{**} & -0.011 \tnote{**}             \\*
            & (0.005)           & (0.005)                       \\
    \addlinespace
big\_roadsCon
            & - 1.595 \tnote{***}& -1.763 \tnote{***}           \\*
            & (0.170)           & (0.170)                       \\
    \addlinespace
lrailways   & 0.036 \tnote{***} & 0.032 \tnote{***}             \\*
            & (0.003)           & (0.003)                       \\
    \addlinespace
 allgoods   & 0.00004 \tnote{***}& 0.0001 \tnote{***}           \\*
            & (0.00001)         & (0.00001)                     \\
    \addlinespace
rental      & -0.00004 \tnote{***}& -0.0001 \tnote{***}         \\*
            & (0.00000)         & (0.00000)                     \\
    \addlinespace
lIncome     & 0.081 \tnote{***} & 0.075 \tnote{***}             \\
            & (0.010)           & (0.008)                       \\
    \addlinespace
EducShort   & -0.104 \tnote{***}& -0.100 \tnote{***}            \\*
            & (0.014)           & (0.014)                       \\
    \addlinespace
EducMed     & -0.032 \tnote{***}& -0.031 \tnote{***}            \\*
            & (0.005)           & (0.004)                       \\
    \addlinespace
Wealth      & -0.001 \tnote{***}&                               \\*
            & (0.0002)          &                               \\
    \addlinespace
Single      & -0.013 \tnote{**} &                               \\*
            & (0.006)           &                               \\
    \addlinespace
shopservice & 0.003 \tnote{***} &                               \\*
            & (0.0004)          &                               \\
    \addlinespace
residents   & -0.00000 \tnote{***}&                             \\*
            & (0.00000)         &                               \\
    \addlinespace
rooms       & 0.016 \tnote{***} &                               \\*
            & (0.003)           &                               \\
    \addlinespace
Constant    & 10.165 \tnote{***}& 10.112 \tnote{***}            \\*
            & (0.047)           & (0.034)                       \\
    \midrule
Observations        & {8,880}   & {8,880}                       \\*
    \addlinespace
$R ^{2}$            & {0.809}   & {0.806}                       \\*
Adjusted R$^{2}$    & 0.809     & 0.805                         \\
    \addlinespace
Residual Std. Error & 0.189     & 0.190                         \\
            & {(df = 8854)}     & {(df = 8859)}                 \\
    \addlinespace
F Statistic & \num{1 501 224}\tnote{***}
                                & \num{1 837 336}\tnote{***}    \\
            & {(df = 25; 8854)} & {(df = 20; 8859)}             \\
\end{tabularx}
    \end{ThreePartTable}
\end{document}

注意:\\*表中以 结尾的行,在它们之后禁止拆分表。

相关内容