0

I want to fit my two tables that contains 7 column headers, here is my code :

\documentclass[preprint,12pt,authoryear]{elsarticle}


      %------------------------------------------------------------------------------------------------------------------------------------------
 \usepackage[margin=2cm]{geometry}
 \usepackage[figurename=Fig.]{caption}
 \usepackage{tabulary}
 \usepackage{tabularx}
 \usepackage{varioref}
 \usepackage{commath}
  \usepackage{array,multirow}
  \usepackage{threeparttable}  
  \usepackage{longtable}
  \usepackage{tabulary}
  \usepackage{booktabs}
  \usepackage{float}
  \usepackage{caption}
 \usepackage{subcaption}
 \usepackage[table]{xcolor}

  \begin{document}
    \begin{table}[H]
 \rowcolors{2}{}{lightgray}
 \centering
 \caption{Balance information for outcome variables at baseline.}
 \label{tab:multi row}
 \begin{tabular}{p{3cm} p{3cm} p{1cm}p{3cm}p{1cm}p{2cm} p{2cm}p{2cm}}
  \hline
&Mean control & SD & Mean treatment & SD & Difference & SD & N \\
\hline
\cellcolor{lightgray} WHO&1.53 & 0.55 & 1.50&0.58&-0.03&(0.04)&856 \\
&  \\
 \cellcolor{lightgray}Hopkins & 0.93& 0.60& 0.99& 0.62& 0.06& (0.04)& 856\\
 &  \\
 \cellcolor{lightgray}Satisfied &3.07& 1.67& 3.17& 1.71& 0.10& (0.12)& 856 \\
 &  \\
 \cellcolor{lightgray}Problems &0.14& 0.37& 0.13& 0.35& -0.01& (0.03)& 559\\
&  \\
      \hline
      \end{tabular}
      \end{table}%


\begin{table}[H]
 \centering
  \def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}
  \caption{Chiefdom Level Analysis}
   \begin{tabular}{l*{7}{c}}
      \hline\hline
                  &\multicolumn{1}{c}{(1)}&\multicolumn{1}{c}{(2)}&\multicolumn{1}{c}{(3)}&\multicolumn{1}{c}{(4)}&\multicolumn{1}{c}{(5)}&\multicolumn{1}{c}{(6)}&\multicolumn{1}{c}{(7)}\\
                 &\multicolumn{1}{c}{Total} &\multicolumn{1}{c}{Parent talks loudly}&\multicolumn{1}{c}{Friendship helping}&\multicolumn{1}{c}{online courses}&\multicolumn{1}{c}{Trust mean}&\multicolumn{1}{c}{Learning remotely}&\multicolumn{1}{c}{Mean Effects index}\\
          \hline
           Treatment           &      -0.116         &      -0.091         &      -0.032         &      -0.171         &      -0.473\sym{***}&      -0.068         &      -0.325         \\
                &     (0.368)         &     (0.106)         &     (0.103)         &     (0.103)         &     (0.176)         &     (0.109)         &     (0.278)         \\
          Total               &       0.146         &                     &                     &                     &                     &                     &                     \\
                &     (0.112)         &                     &                     &                     &                     &                     &                     \\
      Parent talks loudly &                     &       0.409\sym{***}&                     &                     &                     &                     &                     \\
                &                     &     (0.124)         &                     &                     &                     &                     &                     \\
      Friendship helping  &                     &                     &       0.458\sym{***}&                     &                     &                     &                     \\
                &                     &                     &     (0.126)         &                     &                     &                     &                     \\
      Online courses      &                     &                     &                     &       1.027\sym{***}&                     &                     &                     \\
                &                     &                     &                     &     (0.068)         &                     &                     &                     \\
 Trust mean          &                     &                     &                     &                     &       0.017         &                     &                     \\
                &                     &                     &                     &                     &     (0.100)         &                     &                     \\
  Learning remotely   &                     &                     &                     &                     &                     &       1.096\sym{***}&                     \\
                &                     &                     &                     &                     &                     &     (0.088)         &                     \\
   Constant            &       5.288\sym{***}&       0.277\sym{**} &       0.272\sym{**} &      -0.130         &       4.239\sym{***}&      -0.315\sym{**} &       0.165         \\
                &     (0.767)         &     (0.113)         &     (0.126)         &     (0.130)         &     (0.412)         &     (0.136)         &     (0.205)         \\
   \hline
    N                   &     106.000         &     100.000         &     100.000         &     104.000         &      81.000         &      98.000         &     106.000         \\
     R^{2}               &       0.205         &       0.345         &       0.330         &       0.809         &       0.360         &       0.756         &       0.255         \\
\hline\hline
 \multicolumn{8}{l}{\footnotesize t-statistics are between parentheses. Statistical significance at \enspace *** $p < 0.01$; \enspace ** $p < 0.05$;\enspace * $p < 0.10$}\\
  \end{tabular}
  \end{table}
 \end{document}

my output :

enter image description here

1
  • The main problem seems to be the headers. You should make them with the \thead command, from makecell: you can have multiline headers.
    – Bernard
    Commented Mar 17, 2022 at 10:39

1 Answer 1

1

Hm, if consider @Bernard comment, than your tables becomes:

enter image description here

\documentclass[preprint,12pt,authoryear]{elsarticle}
%------------------------------------------------------------------------------------------------------------------------------------------
\usepackage[margin=2cm]{geometry}
\usepackage[figurename=Fig.]{caption}
\usepackage{tabulary}
\usepackage{tabularx}
\usepackage{varioref}
\usepackage{commath}
\usepackage{array, makecell, multirow}
\usepackage{threeparttable}
\usepackage{longtable}
\usepackage{tabulary}
\usepackage{booktabs}
\usepackage{float}
\usepackage{caption}
\usepackage{subcaption}
\usepackage[table]{xcolor}

  \begin{document}
    \begin{table}[H]
 \rowcolors{2}{}{lightgray}
 \centering
 \caption{Balance information for outcome variables at baseline.}
 \label{tab:multi row}
 \begin{tabular}{ >{\columncolor{lightgray}}l *{7}{c} } 
    \hline
     &  \thead{Mean\\ control}
            & SD
                &   \thead{Mean\\ treatment}
                    &   SD
                        &   Difference
                            &   SD
                                &   N               \\
    \hline
WHO & 1.53 & 0.55 & 1.50 & 0.58 & -0.03 & (0.04) & 856 \\
    &  \\
Hopkins & 0.93& 0.60& 0.99& 0.62& 0.06& (0.04)& 856\\
    &  \\
Satisfied &3.07& 1.67& 3.17& 1.71& 0.10& (0.12)& 856 \\
    &  \\
Problems &0.14& 0.37& 0.13& 0.35& -0.01& (0.03)& 559\\
    &  \\
    \hline
      \end{tabular}
      \end{table}%


\begin{table}[H]
 \centering
  \def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}
  \caption{Chiefdom Level Analysis}
   \begin{tabular}{l*{7}{c}}
      \hline\hline
    & (1)   & (2) & (3) & (4) & (5) & (6) & (7)  \\
    & Total & \thead{Parent\\ talks\\ loudly}
                &  \thead{Friendship\\ helping}
                    &  \thead{online\\ courses}
                        & \thead{Trust\\ mean} 
                            & \thead{Learning\\ remotely}
                                & \thead{Mean\\ Effects\\ index} \\
          \hline
           Treatment           &      -0.116         &      -0.091         &      -0.032         &      -0.171         &      -0.473\sym{***}&      -0.068         &      -0.325         \\
                &     (0.368)         &     (0.106)         &     (0.103)         &     (0.103)         &     (0.176)         &     (0.109)         &     (0.278)         \\
          Total               &       0.146         &                     &                     &                     &                     &                     &                     \\
                &     (0.112)         &                     &                     &                     &                     &                     &                     \\
      Parent talks loudly &                     &       0.409\sym{***}&                     &                     &                     &                     &                     \\
                &                     &     (0.124)         &                     &                     &                     &                     &                     \\
      Friendship helping  &                     &                     &       0.458\sym{***}&                     &                     &                     &                     \\
                &                     &                     &     (0.126)         &                     &                     &                     &                     \\
      Online courses      &                     &                     &                     &       1.027\sym{***}&                     &                     &                     \\
                &                     &                     &                     &     (0.068)         &                     &                     &                     \\
 Trust mean          &                     &                     &                     &                     &       0.017         &                     &                     \\
                &                     &                     &                     &                     &     (0.100)         &                     &                     \\
  Learning remotely   &                     &                     &                     &                     &                     &       1.096\sym{***}&                     \\
                &                     &                     &                     &                     &                     &     (0.088)         &                     \\
   Constant            &       5.288\sym{***}&       0.277\sym{**} &       0.272\sym{**} &      -0.130         &       4.239\sym{***}&      -0.315\sym{**} &       0.165         \\
                &     (0.767)         &     (0.113)         &     (0.126)         &     (0.130)         &     (0.412)         &     (0.136)         &     (0.205)         \\
   \hline
    N                   &     106.000         &     100.000         &     100.000         &     104.000         &      81.000         &      98.000         &     106.000         \\
    $R^{2}$               &       0.205         &       0.345         &       0.330         &       0.809         &       0.360         &       0.756         &       0.255         \\
\hline\hline
 \multicolumn{8}{p{\linewidth}}{\footnotesize t-statistics are between parentheses. Statistical significance at \enspace *** $p < 0.01$; \enspace ** $p < 0.05$;\enspace * $p < 0.10$}\\
  \end{tabular}
  \end{table}
 \end{document}

However, I would take long table from R exceeds page width as an example how to write similar table(s).

1
  • Huùùm believe me I tried to follow your answer to that question, u saved me my friend thanks a lot
    – HAITHEM
    Commented Mar 17, 2022 at 11:21

You must log in to answer this question.

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