1

I have a small question. I am compiling my tables in LaTeX. I wrote the following code:

\begin{table}[htbp]\centering\footnotesize{
\def\sym#1{\ifmmode^{#1}\else\(^{#1}\)\fi}
\caption{Baseline model \label{table3}}
\begin{tabular}{l*{6}{c}}
\hline\hline
&\multicolumn{2}{c}{First Model}&\multicolumn{4}{c}{Second Model}\\
&\multicolumn{1}{c}{(1)}&\multicolumn{1}{c}{(2)}&\multicolumn{1}{c}{(3)}&\multicolumn{1}{c}{(4)}&\multicolumn{1}{c}{(5)}&\multicolumn{1}{c}{(6)}\\

\hline

Regressor1 &.010***& .009***& & .010***& & .009***\\
           & (.001)& (.001) & & (.001) & & (.001)    \\
Regressor2 &       &        & .016***&   & .016***&\\
           &       &        &  (.002)&   & (.002) & \\
\hline
Observations & 107048 & 107048 & 107048 & 107048 & 107048 & 107048  \\
R$^2$        & .072   & .074   & .080   & .080   & .080   & .080     \\
F-test       & 257.792 & 188.037 & 188.037 & 188.037 & 188.037 & 188.037 \\
log(likelihood) & -3.14e+04 & -3.13e+04 & -6.97e+04 & -6.96e+04 & -6.96e+04&   -6.96e+04   \\
\hline\hline
\multicolumn{7}{l}{\footnotesize * \(p<0.10\), ** \(p<0.05\), *** \(p<0.01\)}\\
\multicolumn{7}{l}{\footnotesize Standard errors in parentheses}\\
\end{tabular}}
\end{table}

The table looks as I need. However, I would like to include a horizontal line under First Model and Second Model headings. Could anyone suggest how to do this?

Thank you in advance for your help.

Dario

  • note size commands do not take an argument so the { (and matching }) should not be used here: \footnotesize{ do you just want \hline after the \\ that ends the row? – David Carlisle Dec 17 '15 at 20:57
  • Dear David, I am not sure I understood your question. Anyway, I try to explain better. I do not want an \hline after First Model and Second Model. I would like to have only a line under First Model and another under Second model. I hope I clarified my point. – Dario Dec 17 '15 at 21:08
  • The only way this makes sense is if the line stretches across columns 2 and 3 (first line) and columns 4-7 (second line). Is that what you want? You can use \cline but the results will be a continuous line across columns 2-7. Your table would benefit from the advice given in the booktabs documentation. – cfr Dec 17 '15 at 21:43
3

Please remember to give complete, compilable code when posting examples. I've invented a page width to make the table fit as it is too wide for the default page layout. A complete example would avoid these kinds of issues and make it a lot easier for people to help you.


Writing

    &\multicolumn{2}{c}{First Model}&\multicolumn{4}{c}{Second Model}\\\cline{2-3}\cline{4-7}

will add lines under the row spanning columns 2-3 and 4-7 respectively. However, the result is extremely unclear:

orig table of results with added clines

The table also seems too squashed in general and the use of double lines is not ideal. It would better to space things out a little, clarify the relationships between the headers and the columns and replace double lines with heavier rules, as happens in professionally typeset tables.

Here's a way of achieving these goals using booktabs and threeparttable (via threeparttablex). This improves the layout, clarifies the relation between the headings and columns and improves the layout of the notes and spacing around the caption.

\documentclass{article}
\usepackage{booktabs}
\usepackage[referable,para]{threeparttablex}
\usepackage[scale=.75]{geometry}
\newcommand*\sym[1]{}
\begin{document}
\begin{table}[htbp]\centering\footnotesize
  \renewcommand*\sym[1]{\ifmmode^{#1}\else\(^{#1}\)\fi}
  \begin{threeparttable}
    \caption{Baseline model \label{tab:description}}
    \begin{tabular}{l*{6}{c}}
      \toprule
      &\multicolumn{2}{c}{First Model}&\multicolumn{4}{c}{Second Model}\\
      \cmidrule(lr){2-3}\cmidrule(lr){4-7}
      &\multicolumn{1}{c}{(1)}&(2)&(3)&(4)&(5)&(6)\\
      \midrule
      Regressor1 &.010\tnote{***}& .009\tnote{***}& & .010\tnote{***}& & .009\tnote{***}\\
      & (.001)& (.001) & & (.001) & & (.001)    \\
      Regressor2 &       &        & .016\tnote{***}&   & .016\tnote{***}&\\
      &       &        &  (.002)&   & (.002) & \\
      \cmidrule(lr){1-7}
      Observations & 107048 & 107048 & 107048 & 107048 & 107048 & 107048  \\
      R$^2$        & .072   & .074   & .080   & .080   & .080   & .080     \\
      F-test       & 257.792 & 188.037 & 188.037 & 188.037 & 188.037 & 188.037 \\
      log(likelihood) & -3.14e+04 & -3.13e+04 & -6.97e+04 & -6.96e+04 & -6.96e+04&   -6.96e+04   \\
      \bottomrule
    \end{tabular}
    \begin{tablenotes}
      \footnotesize
      \item[*]\(p<0.10\),
      \item[**]\(p<0.05\),
      \item[***]\(p<0.01\)\par
      \item[]Standard errors in parentheses
    \end{tablenotes}
  \end{threeparttable}
\end{table}
\end{document}

clarified table of results

  • 1
    Hi, thanks a lot for your ansers guys. In particular, the last one is exactly what I wanted. Next time I will be sure to post the entire code. I apologize. – Dario Dec 18 '15 at 14:30
  • No problem. Glad it helped. – cfr Dec 18 '15 at 21:39

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.