Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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

share|improve this question
    
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
add comment

1 Answer

up vote 14 down vote accepted

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

share|improve this answer
    
Thank you very much. It perfectly works :) –  Günal Jan 1 '13 at 23:10
    
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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.