2

I am have numbers with stars and want to align them by decimal. How is this possible within the longtable environment?

\documentclass[12pt]{report}
\usepackage{longtable}
\begin{document}
\begin{longtable}{lrrrrrr}
\hline
\caption{Estimated price elasticities of BMI} \\
\hline
   & (1)   & (2)   & (3)   & (4)   & (5)   & (6) \\
Log BMI & OLS   & q10   & q25   & q50   & q75   & q90 \\
\hline
\\      
\endfirsthead
\multicolumn{6}{c}%
{{ \tablename\ \thetable{} -- continued from previous page}} \\
\hline
   & (1)   & (2)   & (3)   & (4)   & (5)   & (6) \\
 & OLS   & q10   & q25   & q50   & q75   & q90 \\
 \hline 
\endhead
    Price of rice                        & 0.112*** & 0.071 & 0.068 &     0.113** & 0.161*** & 0.137* \\
                                         & (0.041) & (0.053) & (0.045) & (0.047) & (0.055) & (0.074) \\
    Price of other cereals               & -0.051 & -0.055 & -0.081** & -0.069** & -0.022 & -0.023 \\
                                         & (0.033) & (0.039) & (0.035) & (0.034) & (0.044) & (0.059) \\

 \end{longtable}%

 \end{document}
  • Please transform your example into something compilable – user31729 Sep 7 '15 at 14:48
1

enter image description here

longtable uses tabular internally so any of the usual alignment extensions work, decimal alignment is added by (at least ) dcolumn and siunitx packages, I used dcolumn here. Note this sets the numeric in math mode, which is usually better and sets the ** using a math superscript rather than rely on a text font * being raised. I allow the market to overprint slightly into the inter column space here, to allow the table to fit the page width.

\documentclass[12pt]{report}
\usepackage{longtable,dcolumn}
\begin{document}
\newcommand\hd[1]{\multicolumn{1}{c}{#1}}
\newcommand\zz[1]{^{#1}\!\!}
\setlength\extrarowheight{2pt}
\setlength\tabcolsep{4.5pt}
\begin{longtable}{@{}l*{6}{D..{2.5}}@{}}
\hline
\caption{Estimated price elasticities of BMI} \\
\hline
   & \hd{(1)}   & \hd{(2)}   & \hd{(3)}   & \hd{(4)}   & \hd{(5)}   & \hd{(6)} \\
\hd{Log BMI} & \hd{OLS}   & \hd{q10}   & \hd{q25}   & \hd{q50}   & \hd{q75}   & \hd{q90} \\
\hline
\\      
\endfirsthead
\multicolumn{6}{c}%
{{ \tablename\ \thetable{} -- continued from previous page}} \\
\hline
   & \hd{(1)}   & \hd{(2)}   & \hd{(3)}   & \hd{(4)}   & \hd{(5)}   & \hd{(6)} \\
 & \hd{OLS}   & \hd{q10}   & \hd{q25}   & \hd{q50}   & \hd{q75}   & \hd{q90} \\
 \hline 
\endhead
    Rice                        & 0.112\zz{***} & 0.071 & 0.068 &     0.113\zz{**} & 0.161\zz{***} & 0.137\zz{*} \\
                                         & (0.041) & (0.053) & (0.045) & (0.047) & (0.055) & (0.074) \\
    Other cereals               & -0.051 & -0.055 & -0.081\zz{**} & -0.069\zz{**} & -0.022 & -0.023 \\
                                         & (0.033) & (0.039) & (0.035) & (0.034) & (0.044) & (0.059) \\

 \end{longtable}

 \end{document}
1

with use of siunitx ...

enter image description here

\documentclass[12pt]{report}
\usepackage{geometry}
\usepackage{longtable}
\usepackage{siunitx}

\begin{document}

{\setlength\tabcolsep{4pt}
 \renewcommand\arraystretch{1.2}
 \small 
    \begin{longtable}{l*{6}{S[input-symbols = {()},
                              table-space-text-post={(},
                              table-space-text-post ={)*},
                              table-format=-1.3]}
                          }
\hline
\caption{Estimated price elasticities of BMI} \\
\hline
        & {(1)}     & {(2)}     & {(3)}     & {(4)}     & {(5)}     & {(6)}     \\
Log BMI & {OLS}     & {q10}     & {q25}     & {q50}     & {q75}     & {q90}     \\
    \hline
\endfirsthead
\caption{ -- continued from previous page}                                      \\
    \hline
        & {(1)}     & {(2)}     & {(3)}     & {(4)}     & {(5)}     & {(6)}     \\
Log BMI & {OLS}     & {q10}     & {q25}     & {q50}     & {q75}     & {q90}     \\
    \hline
 \hline
\endhead
Price of rice
        &  0.112*** &  0.071    &  0.068    &  0.113**  &  0.161*** &  0.137*   \\
        & (0.041)   & (0.053)   & (0.045)   & (0.047)   & (0.055)   & (0.074)   \\
Price of other cereals
        & -0.051    & -0.055    & -0.081**  & -0.069**  & -0.022    & -0.023    \\
        & (0.033)   & (0.039)   & (0.035)   & (0.034)   & (0.044)   & (0.059)   \\
    \hline
    \end{longtable}%
}
 \end{document}

note: table seems to be wider than text width. this is reason why in mwe i reduce \tabcolsep to 4pt ans used \small for font size.

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.