3

I have a table made in R with Stargazer however, it is too big to fit a page in LyX. I have tried to use \longtable but it doesn't seem to work (might be doing it wrong). Here is the original code

\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} 

Does anybody know how to make the table fit over two pages? Thank you

  • 1
    Welcome ! Please post a fully compilable Minimal Working Example. Otherwise, it may be very difficult to help you. – BambOo Apr 2 '18 at 10:49
4

A table enviroment cannot be broken across pages. Delete \begin{table}\centering and \end{table}, replace tabular with longtable, move \caption and label to immediately after \begin{longtable}{..}. And add \usepackage{longtable} to the preamble, of course.

enter image description here

\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}
  • This works! Thank you very much! This is obviously one of my first times using Lyx so a helping hand is always appreciated. Fortsat god påske. – Andy Apr 2 '18 at 11:24
2

I propose these improvements, based on siunitx and 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} 

enter image description here enter image description here

  • Thank you very much for your help, it makes the tables look quite nice. – Andy Apr 3 '18 at 11:19
2

with use of the packages ltablex, tabularx, threepartablexandsiunitx` you can improve table appearance:

enter image description here

enter image description here

enter image description here

\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}

note: with \\* are terminated rows in table where after them the break of the table is prohibited.

  • Delete zero score for all these answers :-). Goodbye. – Sebastiano Apr 2 '18 at 16:20
  • @Sebastiano, thank you very much! it seems that op not yet read answers ;-) – Zarko Apr 2 '18 at 16:24
  • Don't worry. The important thing is that I read it. :-) – Sebastiano Apr 2 '18 at 16:27
  • @Zarko, thank you for your help. The tables look quite nice now. Obviously, this is one of my first times working with LyX so it takes some time to get used to. :-) – Andy Apr 3 '18 at 11:18
  • @Andy, compare all three suggested solutions. they quite differ in complexity of writing, exploiting of different packages, consistency in table settings and resulted output. this can be very educative and helpful in writing new tables. if you have some question about code, don't hesitate ask for explanation. – Zarko Apr 3 '18 at 12:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.