3

Does anyone know how to get equal spacing between columns in longtable? My code is attached below. Thanks. Franz

\documentclass[12pt,a4paper]{article} \usepackage[latin1]{inputenc}
\usepackage{import} \usepackage{amsmath} \usepackage{amsfonts}
\usepackage{amssymb} %\usepackage{float} \usepackage{lscape} 
\usepackage{setspace} \usepackage{color} \usepackage{geometry}  
\geometry{a4paper,left=25.4mm,right=25.4mm,top=25.4mm,bottom=25.4mm} 
\usepackage{epsfig} \usepackage{epstopdf} \epstopdfsetup{update} 
\usepackage{booktabs} \usepackage{dcolumn} \usepackage{natbib} 
\usepackage{caption} \usepackage{subcaption} \usepackage{longtable}
\def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}
\setlength{\tabcolsep}{1pt}

\renewcommand{\arraystretch}{.7}
\begin{scriptsize}
\begin{longtable}{l*{7}{c}}
\caption{Unconditional Quantile Wage Regressions: Non-performance paid, 2003-2004 \label{tab rifquantnw0304}}\\
    \hline\hline\endfirsthead\hline\endhead\hline\endfoot\endlastfoot
        &\multicolumn{1}{c}{RIF5}&\multicolumn{1}{c}{RIF10}&\multicolumn{1}{c}{RIF25}&\multicolumn{1}{r}{RIF50}&\multicolumn{1}{c}{RIF75}&\multicolumn{1}{c}{RIF90}&\multicolumn{1}{c}{RIF95}\\
        \hline
    Age                 &      0.0930\sym{**} &      0.0847\sym{***}&       0.127\sym{***}&       0.105\sym{***}      &      0.0275         &      -0.150\sym{***}&      -0.189\sym{***} \\
                        &      (3.14)         &      (4.42)         &      (7.52)         &      (7.04)               &      (1.78)       &     (-6.13)         &     (-5.77)         \\
    Age squared/1000    &      -1.283\sym{***}&      -1.100\sym{***}&      -1.326\sym{***}&      -1.081\sym{***}     &      -0.217         &       1.804\sym{***}&       2.217\sym{***} \\
                        &     (-3.64)         &     (-5.04)         &     (-7.78)         &     (-7.31)         &     (-1.39)       &      (6.95)         &      (6.07)         \\
    Female              &      -0.109\sym{**} &      -0.253\sym{***}&      -0.401\sym{***}&      -0.364\sym{***}     &           -0.227\sym{***}&      -0.186\sym{***}&      -0.129\sym{***} \\
                        &     (-2.66)         &     (-7.56)         &    (-13.53)         &    (-15.18)         &     (-9.87)       &     (-6.54)         &     (-3.98)         \\
    Married             &      0.0324         &     -0.0387         &    -0.00840         &      0.0631\sym{*}       &       0.147\sym{***}&       0.122\sym{***}&       0.118\sym{***}\\
                        &      (0.75)         &     (-1.41)         &     (-0.33)         &      (2.51)         &      (5.68)       &      (4.10)         &      (4.35)         \\
    Number of kids      &     -0.0501         &     -0.0390         &    -0.00465         &     0.00457         &     -0.0178       &    -0.00818         &      0.0195         \\
                        &     (-1.14)         &     (-1.31)         &     (-0.19)         &      (0.21)         &     (-0.75)       &     (-0.22)         &      (0.44)         \\
    Elementary school   &     -0.0545         &      -0.220\sym{**} &      -0.199\sym{***}&      -0.103\sym{**}      &     0.00754         &      0.0672\sym{*}  &       0.122\sym{**} \\
                        &     (-0.52)         &     (-3.06)         &     (-4.76)         &     (-3.19)         &      (0.23)       &      (2.01)         &      (2.93)         \\

    \hline
    Observations        &        5882         &        5882         &        5882         &        5882         &        5882         &        5882         &        5882         \\
    \hline\hline
    \end{longtable}
    \end{scriptsize}
\end{document}
  • @Christian: Many thanks for editing my code. – Marko Jul 28 '14 at 22:23
3

(I realize your question appears to be about getting equal widths between the columns of a longtable. However, since the intercolumn whitespace is given by 2\tabcolsep, the intercolumn widths are already equal. I therefore interpret your question as being about getting the column widths to be equal.)

In the present case, since you're already loading the dcolumn package, you may achieve your objective by (i) defining a new column type named d that does decimal alignment of the numbers and (ii) replacing the c specification with d{3.6}. Doing so will ensure that the d-type columns all have the same width; therefore, the horizontal distances from decimal point to decimal point are constant across adjacent columns.

Separately, since you're loading the booktabs package, you may also want to replace the various \hline instructions with \toprule, \midrule, etc.

It turns out not to be necessary to go to \scriptsize, i.e., a ca. 30% linear reduction in font size, in order to get the table to fit. Executing \footnotesize(which brings about a ca. 20% font size reduction) suffices.

enter image description here

\documentclass[12pt,a4paper]{article} 
\usepackage[latin1]{inputenc} 
%% I've commented out the packages that aren't needed for this MWE
%\usepackage{import} 
%\usepackage{amsmath} 
%\usepackage{amsfonts} 
%\usepackage{amssymb} 
%\usepackage{float} 
%\usepackage{lscape} 
%\usepackage{setspace} 
%\usepackage{color} 
\usepackage[margin=1in]{geometry} 
%\usepackage{epsfig} 
%\usepackage{epstopdf} 
%\epstopdfsetup{update} 
\usepackage{booktabs} 
\usepackage{dcolumn} 
\newcolumntype{d}[1]{D{.}{.}{#1}}
%\usepackage{natbib} 
%\usepackage{caption} 
%\usepackage{subcaption} 
\usepackage{longtable}
\setlength\LTcapwidth{\textwidth}
\def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}
\newcommand\mc[1]{\multicolumn{1}{c}{#1}} % handy shortcut macro
\begin{document}
%%\renewcommand{\arraystretch}{.7}
\begingroup
\setlength{\tabcolsep}{2pt} % default value: 6pt
\footnotesize
\begin{longtable}{@{} l *{7}{d{3.6}} @{}} % replace "c" with "d{3.6}"
\caption{Unconditional Quantile Wage Regressions: Non-performance paid, 2003--2004} 
\label{tab rifquantnw0304}\\
\toprule\endfirsthead
\midrule\endhead
\midrule\endfoot
\bottomrule\endlastfoot
&\mc{RIF5}& \mc{RIF10}& \mc{RIF25}& \mc{RIF50}& \mc{RIF75}& \mc{RIF90}& \mc{RIF95}\\
\midrule
Age                 &      0.0930\sym{**} &      0.0847\sym{***}&       0.127\sym{***}&       0.105\sym{***}      &      0.0275         &      -0.150\sym{***}&      -0.189\sym{***} \\
                    &      (3.14)         &      (4.42)         &      (7.52)         &      (7.04)               &      (1.78)       &     (-6.13)         &     (-5.77)         \\
Age squared/1000    &      -1.283\sym{***}&      -1.100\sym{***}&      -1.326\sym{***}&      -1.081\sym{***}     &      -0.217         &       1.804\sym{***}&       2.217\sym{***} \\
                    &     (-3.64)         &     (-5.04)         &     (-7.78)         &     (-7.31)         &     (-1.39)       &      (6.95)         &      (6.07)         \\
Female              &      -0.109\sym{**} &      -0.253\sym{***}&      -0.401\sym{***}&      -0.364\sym{***}     &           -0.227\sym{***}&      -0.186\sym{***}&      -0.129\sym{***} \\
                    &     (-2.66)         &     (-7.56)         &    (-13.53)         &    (-15.18)         &     (-9.87)       &     (-6.54)         &     (-3.98)         \\
Married             &      0.0324         &     -0.0387         &    -0.00840         &      0.0631\sym{*}       &       0.147\sym{***}&       0.122\sym{***}&       0.118\sym{***}\\
                    &      (0.75)         &     (-1.41)         &     (-0.33)         &      (2.51)         &      (5.68)       &      (4.10)         &      (4.35)         \\
Number of kids      &     -0.0501         &     -0.0390         &    -0.00465         &     0.00457         &     -0.0178       &    -0.00818         &      0.0195         \\
                    &     (-1.14)         &     (-1.31)         &     (-0.19)         &      (0.21)         &     (-0.75)       &     (-0.22)         &      (0.44)         \\
Elementary school   &     -0.0545         &      -0.220\sym{**} &      -0.199\sym{***}&      -0.103\sym{**}      &     0.00754         &      0.0672\sym{*}  &       0.122\sym{**} \\
                    &     (-0.52)         &     (-3.06)         &     (-4.76)         &     (-3.19)         &      (0.23)       &      (2.01)         &      (2.93)         \\

\midrule
Observations        & \mc{5882}         & \mc{5882}         & \mc{5882}         & \mc{5882}         & \mc{5882}         & \mc{5882}         & \mc{5882}         \\
\end{longtable}
\endgroup % end of scope of \footnotesize directive
\end{document}
  • Many thanks for your reply. Your suggestion works perfect for me. Is there a way I can also include a note to this table? I have tried this one just before \end{longtable} but it does not work for me: \multicolumn{8}{l}{\tiny \textit{t} statistics in parentheses}\\ – Marko Jul 28 '14 at 17:17
  • 1
    @Franz - You can make such a note a part of \endlastfoot, right? E.g., \midrule \multicolumn{8}{l}}\textit{t}-statistics in parentheses}\\ \endlastfoot. – Mico Jul 28 '14 at 17:22

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.