[Tex/LaTex] Using multicolumn with booktabs

booktabsmulticolumntables

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}

Best Answer

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.

Related Question