26

I am having problems with tables in latex. Here is what I want:

Regressors                 Model 1                                  Model 2
                   Coefficient1  Lower1  Upper1           Coefficient2  Lower2 Upper2 
$beta_{concern_2}$        0.1903627  0.01208  0.89934           0.17054127  0.12093922 0.389928 

and here is my latex code

\begin{table} [h!]
\begin{center}
\begin{tabular}{lcrl}
\hline 
    \multicolumn{1}{l}{Regressors} & \multicolumn{3}{c}{Model 1 }\\ \hline 
    & Coefficient & Lower limit & Upper Limit  \\
     \multicolumn{3}{r}{Model 2 }\\ 
    & Coefficient & Lower limit & Upper Limit  \\
    $\beta_{concern_2}$     & 0.19036273    &0.01208    &   0.89934  & 0.17054127 & 0.12093922 & 0.389928 \\
    \hline
\end{tabular}
\caption{Regression Coefficients of model 1 and model 2 }
\label{beta}
\end{center}
\end{table}

This does not work as I want. Can someone please fix this?

Thanks

Günal

  • You need as many columns in your table as the maximum number of columns in the largest row. Then you use \multicolumn to span multiple columns. So since you have 7 columns in the last row, your \tabular command needs 7 columns. – Alan Munn Jan 1 '13 at 22:43
  • @Alan, thanks for your comment. I am not sure what you meant. Can you please tell me where the mistake is? – Günal Jan 1 '13 at 22:49
28

Assuming you want your two models side by side, you need as many columns in your table as the maximum number of columns in the largest row. Then you use \multicolumn to span multiple columns. So since you have 7 columns in the last row, your \tabular command needs 7 columns.

Here's a version of your table using the booktabs package, which is highly recommended for all tables:

\documentclass{article}
\usepackage{booktabs}

\begin{document}
\begin{tabular}{lllllll}
\toprule 
    Regressors & \multicolumn{3}{c}{Model 1} & \multicolumn{3}{c}{Model 2}\\

    & Coefficient & Lower limit & Upper Limit
    & Coefficient & Lower limit & Upper Limit  \\
    \midrule
    $\beta_{concern_2}$     & 0.19036273    &0.01208    &   0.89934  & 0.17054127 & 0.12093922 & 0.389928 \\
    \bottomrule
\end{tabular}

output of code

  • 2
    I also need to add vertical borders. I tried \begin{tabular}{|l|l|l|l|l|l|l|}, but it did work for the last border from the left. Any idea how to fix it? – Günal Jan 2 '13 at 8:08
  • 2
    It's generally considered very bad form to put vertical lines in tables (although sometimes they can be useful.) In this case I don't think you should use them. If you read the introduction to the booktabs documentation, you'll see a good argument against using them, and the package is designed so that you don't use them. If you must have them, then don't use the booktabs rules, use regular rules. – Alan Munn Jan 2 '13 at 13:59
  • 2
    I read through the booktabs documentation, but couldn't find any arguments why vertical lines are so bad, only sweeping statements like "Never, ever use vertical rules", "if [information] needs to be separated by a vertical line, then you should use two tables instead", "You should not use vertical rules in tables, end of story". Any source giving a convincing rational why? – benroth Jul 18 '17 at 9:20
  • 1
    @benroth As with many things in typographical practice, this is a somewhat subjective issue, but if you look at tables in almost all scientific journals they eschew vertical lines. Bringhurst's Elements of Typographic Style also says to avoid what he calls "furniture" (rules, boxes, dots). Good typography is art not science, so absolute rules like never do X... can be broken. So a vertical line in a table is sometimes helpful, but most times the table will look better and be more readable without it. – Alan Munn Jul 18 '17 at 14:54
  • 1
    @Günal Bit of a late response but it came up as the first result on Google for me - Add vertical borders using \multicolumn{3}{|c|}{Your text here} – CraftedCart Jun 13 '18 at 23:08

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.