2

This is the code I have used

\documentclass[12pt]{article}
\usepackage{fullpage}
\usepackage[british]{babel}
\usepackage{graphicx}
\usepackage{natbib}
\usepackage{booktabs}
\usepackage{longtable}
\usepackage{tikz}
\def\checkmark{\tikz\fill[scale=0.4](0,.35) -- (.25,0) -- (1,.7) -- (.25,.15) -- cycle;} 
\linespread{1.2}

\begin{longtable}{@{}llllll@{}}
\caption{}
\label{Table 2}\\
Regression 1B: & & & 
\\
\endfirsthead
%
\multicolumn{6}{c}%
{{\bfseries Table \thetable\ continued from previous page}} \\
\endhead
%
\multicolumn{6}{l}{2012 reform} \\* \midrule

Logit estimates                                              & Model 1 & Model 2  & Model 3  & Model 4                   & Model 5                   \\* \midrule
Entry year      & -.091***      & -.077***      & -.063***                      & -.102***                  & -.064***                  \\
                                                             & (0.000) & (0.000)  & (0.001)  & (0.003)                   & (0.002)                   \\
Female                                                       &         & .883***  & .833***  & .798***                   & .833***                   \\
                                                             &         & (0.000)  & (0.000)  & (0.000)                   & (0.000)                   \\
BAME                                                         &         & -.700*** & -.618*** & -.618***                  & -.620                     \\
                                                             &         & (0.000)  & (0.000)  & (0.000)                   & (0.000)                   \\
Female x entry year                            &         &          &          & \checkmark &                           \\
BAME x entry year                              &         &          &          &                           & \checkmark \\* \midrule
Controls                      &               &               & \checkmark     & \checkmark & \checkmark \\* \midrule
Observations                                                 & 165,280 & 165,280  & 165,280  & 165,280                   & 165,282                   \\
Reported coefficients; p-values in parentheses               &         &          &          &                           &                           \\
*** p\textless{}0.01, ** p\textless{}0.05, * p\textless{}0.1 &         &          &          &                           &                          
\end{longtable}

This is what I get: enter image description here

How do I make the table stay within the page borders. As it currently goes off to the right and also overlaps the page number at the bottom too

5
  • Why do you use longtable for such a short table? It could easily fit onto a single page.
    – leandriis
    Apr 12, 2021 at 9:45
  • 1
    Regarding the width issue, \multicolumn{6}{l}{Reported coefficients; p-values in parentheses} should help in order to reduce the width of the currently overly wide first column.
    – leandriis
    Apr 12, 2021 at 9:46
  • @leandriis great thank you!
    – susan
    Apr 12, 2021 at 10:50
  • A random remark --- I'd suggest using $\times$ rather x for the interaction terms, that'll give you a proper multiplication sign and look better. Also, using $-$ rather than just - for the negative coefficients will give you a proper minus sign rather than a dash. And finally, you might want $p < 0.01$ etc.
    – chsk
    Apr 13, 2021 at 7:24
  • 1
    @chsk really useful thank you
    – susan
    Apr 14, 2021 at 7:45

2 Answers 2

1

The straightforward way is to create a \multicolumn of the last two rows.

b

\documentclass[12pt]{article}
\usepackage{fullpage}
\usepackage[british]{babel}
\usepackage{graphicx}
\usepackage{natbib}
\usepackage{booktabs}
\usepackage{longtable}
\usepackage{tikz}
\def\checkmark{\tikz\fill[scale=0.4](0,.35) -- (.25,0) -- (1,.7) -- (.25,.15) -- cycle;} 
\linespread{1.2}    

\begin{document}    

\begin{longtable}{@{}llllll@{}}
    \caption{}
    \label{Table 2}\\
    Regression 1B: & & & 
    \\
    \endfirsthead
    %
    \multicolumn{6}{c}%
    {{\bfseries Table \thetable\ continued from previous page}} \\
    \endhead
    %
    \multicolumn{6}{l}{2012 reform} \\* \midrule
    
    Logit estimates                                              & Model 1 & Model 2  & Model 3  & Model 4                   & Model 5                   \\* \midrule
    Entry year      & -.091***      & -.077***      & -.063***                      & -.102***                  & -.064***                  \\
    & (0.000) & (0.000)  & (0.001)  & (0.003)                   & (0.002)                   \\
    Female                                                       &         & .883***  & .833***  & .798***                   & .833***                   \\
    &         & (0.000)  & (0.000)  & (0.000)                   & (0.000)                   \\
    BAME                                                         &         & -.700*** & -.618*** & -.618***                  & -.620                     \\
    &         & (0.000)  & (0.000)  & (0.000)                   & (0.000)                   \\
    Female x entry year                            &         &          &          & \checkmark &                           \\
    BAME x entry year                              &         &          &          &                           & \checkmark \\* \midrule
    Controls                      &               &               & \checkmark     & \checkmark & \checkmark \\* \midrule
    Observations                                                 & 165,280 & 165,280  & 165,280  & 165,280                   & 165,282                   \\ \bottomrule
    \multicolumn{6}{l}{Reported coefficients; p-values in parentheses}                   \\
    \multicolumn{6}{l}{ *** p\textless{}0.01, ** p\textless{}0.05, * p\textless{}0.1} 
\end{longtable}
0
  • Are you really need longtable? From code fragment can be concluded that no, so instead of long table you can use for example tabularx and for notes below table use tablenotes determined by \threeparttablex:
\documentclass[12pt]{article}
\usepackage{fullpage}
\usepackage{dingbat}

\usepackage[skip=1ex]{caption}
\usepackage{booktabs, xltabular}
    \newcolumntype{C}{>{\centering\arraybackslash}X}
    \NewExpandableDocumentCommand\mcx{O{1}m}{\multicolumn{#1}{X}{#2}}
\usepackage[referable]{threeparttablex}
\usepackage{siunitx}
%---------------------------------------------------------------%
\usepackage{lipsum}% For dummy text. Don't use in a real document

\begin{document}
\lipsum[1-2]
    \begin{table}[ht]
\sisetup{table-space-text-pre={(},
         table-align-text-pre=false,
         table-space-text-post={***},
         table-align-text-post=false,
         input-open-uncertainty = ,
         input-close-uncertainty = ,
         table-format=-1.3
         }
\begin{threeparttable}
\caption{My long table}
    \label{Table 2}                                             
\begin{tabularx}{\linewidth}{@{} l *{5}{S} @{}}
    \toprule
\multicolumn{6}{@{} l}{2012 reform}                                 \\* 
    \midrule
\multicolumn{6}{@{} l}{Regression 1B:}                              \\
Logit estimates
    & \mcx{Model 1} & \mcx{Model 2} & \mcx{Model 3} & \mcx{Model 4} & \mcx{Model 5} \\* 
    \midrule
Entry year      
    & -.091***  & -.077***  & -.063***  & -.102***  & -.064***  \\
    & (0.000)   & (0.000)   & (0.001)   & (0.003)   & (0.002)   \\
Female                                                       
    &           & .883***   & .833***   & .798***   & .833***   \\
    &           & (0.000)   & (0.000)   & (0.000)   & (0.000)   \\
BAME                                                         
    &           & -.700***  & -.618***  & -.618***  & -.620     \\
    &           & (0.000)   & (0.000)   & (0.000)   & (0.000)   \\
Female x entry year                            
    &           &           &           &\checkmark &           \\
BAME x entry year                              
    &           &           &           &           &\checkmark \\* 
    \midrule
Controls                      
    &           &           &\checkmark & \checkmark &\checkmark \\* 
    \midrule
Observations                                                 
    & {165,280} & {165,280} & {165,280} & {165,280} & {165,282} \\
    \bottomrule
\end{tabularx}
\begin{tablenotes}[para,flushleft]\footnotesize
\note{
Reported coefficients; $p$-values in parentheses:
\item[***]  $p<0.01$,
\item[**]   $p<0.05$,
\item[*]    $p<0.1$
     }
    \end{tablenotes}
\end{threeparttable}
    \end{table}
\lipsum[3]
\end{document}

enter image description here

  • If you for some unknown reason persist to brake your table between pages, than I would consider to use xltabular and threeparttablex packages. Also for better align of numbers I would employ siunitx package and for \checkmark use fonts dingbat:
\documentclass[12pt]{article}
\usepackage{fullpage}
\usepackage{dingbat}

\usepackage[skip=1ex]{caption}
\usepackage{booktabs, xltabular}
    \newcolumntype{C}{>{\centering\arraybackslash}X}
    \NewExpandableDocumentCommand\mcx{O{1}m}{\multicolumn{#1}{C}{#2}}
\usepackage[referable]{threeparttablex} 
\usepackage{siunitx}
%---------------- Show page layout. Don't use in a real document!
\usepackage{showframe}
\renewcommand\ShowFrameLinethickness{0.15pt}
\renewcommand*\ShowFrameColor{\color{red}}
%---------------------------------------------------------------%
\usepackage{lipsum}% For dummy text. Don't use in a real document

\begin{document}
\lipsum[1-4]

    \begingroup
\sisetup{table-space-text-pre={(},
         table-align-text-pre=false,
         table-space-text-post={***},
         table-align-text-post=false,
         input-open-uncertainty = ,
         input-close-uncertainty = ,
         table-format=-1.3
         }
\begin{ThreePartTable}
\begin{TableNotes}[para,flushleft]\footnotesize
\note{Reported coefficients; $p$-values in parentheses:
\item[***]  $p<0.01$,
\item[**]   $p<0.05$,
\item[*]    $p<0.1$
     } 
    \end{TableNotes}
%
\begin{xltabular}{\textwidth}{@{} l *{5}{S} @{}}
\caption{My long table}
    \label{Table 2}                             \\
    \toprule
    Regression 1B: & & &                        \\
    \midrule
\endfirsthead
    \caption[]{ continued from previous page}   \\
\endhead
%\endfoot
    \bottomrule
    \insertTableNotes
\endlastfoot
% table body
\multicolumn{6}{@{} l}{2012 reform}                                 \\* 
    \midrule
\multicolumn{6}{@{} l}{Regression 1B:}                              \\
Logit estimates
    & \mcx{Model 1} & \mcx{Model 2} & \mcx{Model 3} & \mcx{Model 4} & \mcx{Model 5} \\* 
    \midrule
Entry year      
    & -.091***  & -.077***  & -.063***  & -.102***  & -.064***  \\
    & (0.000)   & (0.000)   & (0.001)   & (0.003)   & (0.002)   \\
Female                                                       
    &           & .883***   & .833***   & .798***   & .833***   \\
    &           & (0.000)   & (0.000)   & (0.000)   & (0.000)   \\
BAME                                                         
    &           & -.700***  & -.618***  & -.618***  & -.620     \\
    &           & (0.000)   & (0.000)   & (0.000)   & (0.000)   \\
Female x entry year                            
    &           &           &           &\checkmark &           \\
BAME x entry year                              
    &           &           &           &           &\checkmark \\* 
    \midrule
Controls                      
    &           &           &\checkmark & \checkmark &\checkmark \\* 
    \midrule
Observations                                                 
    & {165,280} & {165,280} & {165,280} & {165,280} & {165,282} \\
\end{xltabular}
\end{ThreePartTable}
    \endgroup
    
\lipsum[5]
\end{document}

enter image description here

(red lines indicate page layout)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .