5

enter image description here

I am trying to make a table outlined by the codes below, but I am not able to use the multicolumn command. I need the header 'Share' over the 2nd, 3rd, and 4th column of Men, Women and pooled respectively. And the header 'Avg hourly wage' over the 5th, 6th, 7th column of Men, Women and pooled respectively. The code is attached below.

Any help is greatly appreciated!

    \begin{document}
    \documentclass[10.5pt,a4]{article}
    \usepackage[margin=0.5in,a4paper]{geometry}
    \usepackage{booktabs}
    \usepackage{caption}
    \usepackage{float}
    \usepackage{titlesec}
    \usepackage{capt-of}

     %dashed line
    \usepackage{array}
    \usepackage{arydshln}
    \setlength\dashlinedash{0.2pt}
    \setlength\dashlinegap{1.5pt}
    \setlength\arrayrulewidth{0.3pt}

    %Widows & Orphans & Penalties

    \widowpenalty500
    \clubpenalty500
    \clubpenalty=9996
    \exhyphenpenalty=50 %for line-breaking at an explicit hyphen
   \brokenpenalty=4991
   \predisplaypenalty=10000
   \postdisplaypenalty=1549
   \displaywidowpenalty=1602
   \floatingpenalty = 20000


   \begin{table*}[] \centering
   %\ra{1.3}
    \begin{small}
   \begin{tabular}{@{}lrrrrrrr@{}}\toprule
   \textbf{Dependent Variables} & & \textbf{Share(\%)} & & \textbf{Avg hourly wage} & & & \textbf{Avg differential} \\ \hline
   & \textbf{Men} & \textbf{Women} & \textbf{Pooled} & \textbf{  Men  } & 
   \textbf{Women} & \textbf{Pooled} \\ \hdashline
   \\
   \textbf{PANEL A: 2011-2012}\ \\ \midrule
   \\
   Panel A.1: Sector (Urban or Rural)\ \\ \hdashline
   Rural  & 51.5 & 54 & 52 & 28.54 & 18.83 & 26.92 & 51.5 \\ \hdashline
   Urban & 48.4 & 46 & 48 & 45.19 & 41.86 & 45 & 7.8 \\ \hdashline
  \\
   Panel A.2: Sector (Public or Private) \\ \hdashline
   Public & 18.6 & 27.7 & 20 & 75.55 & 55.44 & 71.1 & 36.2 \\ \hdashline
   Private & 81.4 & 72.3 & 80 & 27.68 & 19.67 & 26.52 & 40.7 \\ \hdashline
  \\
  \\
  %(further columns omitted)
  \end{tabular}
  \end{small}
  \caption{Summary statistics 2}
  \end{table*}

   \end{document}
3
  • Welcome to TeX.SX! Please help us (and also you) and add a minimal working example (MWE). Your code does not contain \begin{document}, isen't minimal and does not compile. Please use the edit button. A related question is here: How to multicolumn in booktabs?
    – Bobyandbob
    Commented Aug 20, 2017 at 5:38
  • 1
    I would advice to not use the dashed lines. They are more confusing than helping.
    – Johannes_B
    Commented Aug 20, 2017 at 6:35
  • Off-topic: The article document class doesn't recognize -- and hence ignores -- the option 10.5pt.
    – Mico
    Commented Aug 20, 2017 at 7:45

2 Answers 2

6

Like this?

enter image description here

changes:

  • introduced are three new packages: malecell (for two line headers), multirow for multi row cells and siunitx (for column type S)
  • headers of group of columns are in \multicolumn{3}{l}{...}
  • for intermediate header is used \multicolumn{8}{l}{...}
  • in columns with number the column type is changed to S

    \documentclass[11pt]{article}
    \usepackage[margin=0.5in,a4paper]{geometry}
    \usepackage{caption}
    %    \usepackage{float}
    %    \usepackage{titlesec}
    %    \usepackage{capt-of}

     %dashed line
    \usepackage{array, booktabs, makecell, multirow}
    \renewcommand\theadfont{\bfseries\small}
    \newcommand\mceight[1]{\multicolumn{8}{l}{#1}}
    \usepackage{arydshln}
    \setlength\dashlinedash{0.2pt}
    \setlength\dashlinegap{1.5pt}
    \setlength\arrayrulewidth{0.3pt}

\usepackage{siunitx}

\begin{document}
   \begin{table}[ht] \centering
   \small
   \begin{tabular}{ l*{7}{S[table-format=2.2]} }
   \toprule
\multirow[b]{2}{*}{\thead{Dependent\\ Variables}
    &   \multicolumn{3}{c}{\thead[b]{Share(\%)}}
        & \multicolumn{3}{c}{\thead[b]{Avg hourly wage}}
            & {\multirow[b]{2}{*}{\thead{Avg\\ differential}}}              \\
    \cmidrule(lr){2-4}\cmidrule(lr){5-7}
    & \textbf{Men} & \textbf{Women} & \textbf{Pooled}
    & \textbf{Men} & \textbf{Women} & \textbf{Pooled}                       \\
   \hdashline                                                               \\
   \mceight{\textbf{PANEL A: 2011-2012}}                                    \\
   \midrule
   \\
   \mceight{Panel A.1: Sector (Urban or Rural)}                             \\ \hdashline
   Rural  & 51.5 & 54 & 52 & 28.54 & 18.83 & 26.92 & 51.5                   \\ \hdashline
   Urban  & 48.4 & 46 & 48 & 45.19 & 41.86 & 45    & 7.8                    \\ \hdashline                                                               \\
   \mceight{Panel A.2: Sector (Public or Private)}                          \\ \hdashline
   Public  & 18.6 & 27.7 & 20 & 75.55 & 55.44 & 71.1 & 36.2                 \\ \hdashline
   Private & 81.4 & 72.3 & 80 & 27.68 & 19.67 & 26.52 & 40.7                \\ \hdashline                                                               \\
   \mceight{Panel A.3: Education level}                                     \\ \hdashline
   Illilerate       & 11.7  & 27.7  & 14.3 & 21.11 & 13.92 & 18.87 & 51.6   \\ \hdashline
   primary          & 14.5  & 14.1  & 14.4 & 23.02 & 14.36 & 21.6  & 60.3   \\
   \hdashline
   secondary        & 46.1  & 26.08 & 42.9 & 30.13 & 20.29 & 29.17 & 48.49  \\
   \hdashline
   higher secondary & 12.12 & 11.1  & 11.9 & 43.13 & 39.6  & 42.6  & 8.9    \\
   \hdashline
   graduate         & 9.9   & 11.21 & 10.1 & 67.03 & 58.84 & 65.58 & 13.91  \\
   \hdashline
   post graduate    & 5.45 & 9.7   & 6.1   & 89.82 & 74.42 & 85.51 & 20.69  \\
   \bottomrule
  \end{tabular}
  \end{small}
  \caption{Summary statistics 2}
  \end{table}
\end{document}

note:

  • package caption contain capt-of features, so there is no need to load it
  • reconsider, if all dashed lines are necessary (i would delete most of them)

addendum: In case that you like to have table over more pages, the use of longtable is possible solution:

enter image description here

\documentclass{article}
\usepackage[margin=1in,a4paper]{geometry}
\usepackage{caption}

\usepackage{array, booktabs, longtable, makecell, multirow}
\renewcommand\theadfont{\bfseries\small}
\newcommand\mceight[1]{\multicolumn{8}{l}{#1}}

\usepackage{arydshln}
\setlength\dashlinedash{0.2pt}
\setlength\dashlinegap{1.5pt}
\setlength\arrayrulewidth{0.3pt}
\usepackage{siunitx}

\usepackage{lipsum}% for dummy text

\begin{document}
\lipsum[1-5]% text filler that table is two pages
   \begin{longtable}{ l*{7}{S[table-format=2.2]} }
\caption{Summary statistics 2}
\label{tab:...}                                                             \\
\toprule
\multirow[b]{2}{*}{\thead{Dependent\\ Variables}}
    &   \multicolumn{3}{c}{\thead[b]{Share(\%)}}
        & \multicolumn{3}{c}{\thead[b]{Avg hourly wage}}
            & {\multirow[b]{2}{*}{\thead{Avg\\ differential}}}              \\
    \cmidrule(lr){2-4}\cmidrule(lr){5-7}
    & \textbf{Men} & \textbf{Women} & \textbf{Pooled}
    & \textbf{Men} & \textbf{Women} & \textbf{Pooled}                       \\
   \hdashline                                                               \\
\endfirsthead
%%%%
\caption{Summary statistics 2 (cont.)}                                      \\
\toprule
\multirow[b]{2}{*}{\thead{Dependent\\ Variables}}
    &   \multicolumn{3}{c}{\thead[b]{Share(\%)}}
        & \multicolumn{3}{c}{\thead[b]{Avg hourly wage}}
            & {\multirow[b]{2}{*}{\thead{Avg\\ differential}}}              \\
    \cmidrule(lr){2-4}\cmidrule(lr){5-7}
    & \textbf{Men} & \textbf{Women} & \textbf{Pooled}
    & \textbf{Men} & \textbf{Women} & \textbf{Pooled}                       \\
    \midrule                                                                \\
\endhead
\midrule
\multicolumn{8}{r}{\footnotesize\textit{Continue on the next page}}
\endfoot
\endlastfoot
%%%%        
\mceight{\textbf{PANEL A: 2011-2012}}                                    \\
\midrule
\\
\mceight{Panel A.1: Sector (Urban or Rural)}                             \\ \hdashline
Rural  & 51.5 & 54 & 52 & 28.54 & 18.83 & 26.92 & 51.5                   \\ 
Urban  & 48.4 & 46 & 48 & 45.19 & 41.86 & 45    & 7.8                    \\ \\    \mceight{Panel A.2: Sector (Public or Private)}                          \\ \hdashline
Public  & 18.6 & 27.7 & 20 & 75.55 & 55.44 & 71.1 & 36.2                 \\ Private & 81.4 & 72.3 & 80 & 27.68 & 19.67 & 26.52 & 40.7                \\ \\    \mceight{Panel A.3: Education level}                                     \\ \hdashline
Illilerate       & 11.7  & 27.7  & 14.3 & 21.11 & 13.92 & 18.87 & 51.6   \\ primary          & 14.5  & 14.1  & 14.4 & 23.02 & 14.36 & 21.6  & 60.3   \\
secondary        & 46.1  & 26.08 & 42.9 & 30.13 & 20.29 & 29.17 & 48.49  \\
higher secondary & 12.12 & 11.1  & 11.9 & 43.13 & 39.6  & 42.6  & 8.9    \\
graduate         & 9.9   & 11.21 & 10.1 & 67.03 & 58.84 & 65.58 & 13.91  \\
post graduate    & 5.45 & 9.7   & 6.1   & 89.82 & 74.42 & 85.51 & 20.69  \\
\bottomrule
    \end{longtable}
\end{document}

edit: For longtable solution now i stole some idea (regarding first and last columns header) from Mico answer ... and add \midrule for the \endfoot.

9
  • Thanks a ton, this works perfectly! Also, one more thing, is there a way I could break this table into multiple pages rather than compressing it in one single page? Commented Aug 20, 2017 at 6:55
  • 1
    yes, with use of longtable.
    – Zarko
    Commented Aug 20, 2017 at 6:57
  • @KushaVerma, see addendum to my answer.
    – Zarko
    Commented Aug 20, 2017 at 7:16
  • I'd get rid of the document class option 10.5pt: It's not recognized (and hence is ignored) by the article document class. Also, are the cmidrules below the 1st and 8th columns needed/helpful?
    – Mico
    Commented Aug 20, 2017 at 8:13
  • 1
    @Mico, thanks for comment. i consider it in my answer edit [and mentioned, where i stole something :-)]. about font size you have right. now i removed option 10.5 points at longtable example. thank you!
    – Zarko
    Commented Aug 20, 2017 at 8:40
2

Here's a solution which (a) uses a longtable environment instead of a nested table/tabular environment, (b) aligns the numbers in the numeric columns on their decimal markers and (c) provides a bit more structure to the first column.

Note that I've also dispensed with all \hdashline directives: they're simply not needed to communicate the content of the table to your readers. All the dashed lines do, then, is create visual clutter. Get rid of clutter. Your readers will appreciate it. :-)

enter image description here

\documentclass[10pt,a4paper]{article}
    \usepackage[margin=2.5cm,a4paper]{geometry}
    \usepackage{booktabs}
    \usepackage[font=bf]{caption}
    \usepackage{siunitx,ragged2e,longtable}

% Macro for typesetting multi-line header cells in bold
\newcommand{\boldblock}[1]{%
  \smash{%
  \begin{tabular}[t]{@{}>{\bfseries\arraybackslash}c@{}}
  #1 
  \end{tabular}}}

% Set up a custom column type for the first column:
\newlength\mylength
\settowidth\mylength{Panel A.2: Sector (Public}
\newcolumntype{L}{@{}>{%
  \RaggedRight\hangindent=1em\hangafter=1}p{\mylength}}

\begin{document}

\begin{longtable}{@{} L 
                      *{2}{S[table-format=2.1]}
                      S[table-format=2.0] 
                      *{3}{S[table-format=2.2]} 
                      S[table-format=2.1] @{}}
%% Headers and footers
   \caption{Summary statistics 2} \label{tab:sumstats}\\
   \toprule
   \textbf{Dependent Variables} & 
   \multicolumn{3}{c}{\textbf{Share (\%)}} &  
   \multicolumn{3}{c}{\textbf{Avg hourly wage}} &   
   \boldblock{Avg \\differential} \\ 
   \cmidrule(lr){2-4} \cmidrule(lr){5-7}
   & \textbf{Men} & \textbf{Women} & \textbf{Pooled} 
   & \textbf{Men} & \textbf{Women} & \textbf{Pooled} \\
   \midrule
   \addlinespace
   \endfirsthead

   \multicolumn{8}{@{}l}{Table \ref{tab:sumstats}, cont'd}
   \\ \addlinespace
   \toprule
   \textbf{Dependent Variables} & 
   \multicolumn{3}{c}{\textbf{Share (\%)}} &  
   \multicolumn{3}{c}{\textbf{Avg hourly wage}} &   
   \boldblock{Avg\\differential} \\ 
   \cmidrule(lr){2-4} \cmidrule(lr){5-7}
   & \textbf{Men} & \textbf{Women} & \textbf{Pooled} 
   & \textbf{Men} & \textbf{Women} & \textbf{Pooled} \\
   \midrule
   \addlinespace
   \endhead

   \midrule
   \multicolumn{8}{r@{}}{(cont'd on following page)}\\
   \endfoot

   \bottomrule
   \endlastfoot

%% Body of longtable
   \textbf{PANEL A: 2011--2012} \\
   \addlinespace
   Panel A.1: Sector (Urban or Rural) \\ 
   Rural  & 51.5 & 54 & 52 & 28.54 & 18.83 & 26.92 & 51.5 \\ 
   Urban & 48.4 & 46 & 48 & 45.19 & 41.86 & 45 & 7.8 \\ 
   \addlinespace
   Panel A.2: Sector (Public or Private) \\ 
   Public & 18.6 & 27.7 & 20 & 75.55 & 55.44 & 71.1 & 36.2 \\ 
   Private & 81.4 & 72.3 & 80 & 27.68 & 19.67 & 26.52 & 40.7 \\ 
   \addlinespace
   Panel A.3: Education level \\
   Illiterate &&&&&&& 51.6\\
   \dots\\
   \dots\\
   %% remaining rows omitted

\end{longtable}

\end{document}

You must log in to answer this question.

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