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 created a table in LaTeX, but there are some problems with the borders. The borders remain open whereas I want them closed. Also, in the last row, I want the vertical line gone, ie I want just one column in the last row. Can someone please fix it? Here are my code and my table:

\documentclass{article}
\usepackage{booktabs}

 \begin{document}

 \begin{table} [h!]
\begin{center}
\begin{tabular}{|l|c|c|c|c|}
\hline
Parameters  & \multicolumn{2}{c}{Model 1} & \multicolumn{2}{c}{Model 2}\\ 
    \midrule

&  Coefficient & 95\% CI
&   Coefficient & 95\% CI \\ 
    \midrule

   $\beta_{concern_2}$  &   $0.190^{\ast}$ & (0.113, 0.268) & 0.171 & (0.100, 0.241)\\
   $\beta_{concern_3}$   &  0.117 &  (0.043, 0.191)  & 0.117 & (0.050, 0.183)\\ 
    $\beta_{concern_4}$ & 0.210  &  (0.139, 0.281)  & 0.190 & (0.127, 0.253)\\ 
     $\beta_{concern_5}$ & 0.204 & (0.135, 0.273)   & 0.111 & ( 0.049, 0.173)\\  
    $\beta_{breath_2}$  &  0.157 & (0.07,8 0.236) & 0.208 & (0.136, 0.280) \\
     $\beta_{breath_3}$ & 0.115 & (0.041, 0.189) & 0.100 & (0.034, 0.166) \\
    $\beta_{breath_4}$ & 0.236 &  (0.160, 0.311) & 0.301 & ( 0.234, 0.368)\\  
    $\beta_{breath_5}$ & 0.092 & (0.020, 0.163) & 0.079 & (0.015, 0.144) \\
   $\beta_{weath_2}$  &   0.164 & ( 0.092, 0.236) & 0.137 & (0.071, 0.203) \\
    $\beta_{weath_3}$  & 0.160 &  (0.089, 0.231) & 0.199 & (0.135, 0.263) \\
   $\beta_{weath_4}$ &  0.141 & (0.067, 0.215) & 0.133 & (0.066, 0.199) \\
    $\beta_{weath_5}$ & 0.176 & (0.103, 0.249) &  0.257 & (0.191, 0.323)\\ 
    $\beta_{sleep_2}$  & 0.111 & (0.036, 0.187) & 0.135 & (0.068 0.203)  \\ 
    $\beta_{sleep_3}$  & 0.110 & (0.036 0.184) & 0.176 &  0.110 0.242 \\   
    $\beta_{sleep_4}$  &  0.131 & (0.056 0.205 & 0.162 & 0.095 0.229 \\  
    $\beta_{sleep_5}$  & 0.011 & (-0.064, 0.086) & 0.034 & (-0.033, 0.101) \\ 
    $\beta_{act_2}$ &  0.135 & (0.060, 0.209) & 0.033 & (-0.033, 0.100) \\
    $\beta_{act_3}  $ &0.195 & (0.121, 0.269) & 0.203 & ( 0.137, 0.268)\\  
    $\beta_{act_4}  $ & 0.214 & ( 0.139, 0.290) & 0.254 & (0.186 0.321) \\ 
    $\beta_{act_5}  $ & 0.224 & (0.154, 0.294) & 0.158 & (0.095, 0.221) \\

\hline
    & *statistically significant at 5\% level \\
\hline
\end{tabular}
\caption{Regression Coefficients of model 1 and model 2 }
\label{beta}
\end{center}
\end{table}

 \end{document}

share|improve this question
    
Sorry, but shouldn't you add a | also in the \multicolums (i.e: \multicolumn{2}{c|}{Model 1} )? –  Claudio Fiandrino Jan 2 '13 at 10:57
5  
The commands provided by booktabs work correctly only in absence of vertical rules. Remove them and your table will be better (use also \toprule and \bottomrule, though). –  egreg Jan 2 '13 at 11:07
    
As the Indices are words you could do the follwing $\beta_{\text{concern}_2}$, to do that just add \usepackage{amsmath} to your preamble. –  xfoo Jan 2 '13 at 11:20
    
This is not really a minimum working example. BTW did you read the booktabs documentation? It discourages \hline and |. Perhaps that's why the output looks so bad. –  Marc van Dongen Jan 2 '13 at 11:36

1 Answer 1

up vote 10 down vote accepted

Don't use vertical rules and the appearance of your table will improve immediately.

\documentclass{article}
\usepackage{amsmath}
\usepackage{booktabs}
\usepackage{array}
\newcolumntype{L}{>{$}l<{$}}
\newcolumntype{C}{>{$}c<{$}}
\newcolumntype{R}{>{$}r<{$}}
\newcommand{\nm}[1]{\textnormal{#1}}

\begin{document}

\begin{table} [h!]
\centering
\begin{tabular}{LCRCR}
\toprule
\multicolumn{1}{l}{Parameters} &
\multicolumn{2}{c}{Model 1}    &
\multicolumn{2}{c}{Model 2}    \\ 
\cmidrule(lr){2-3}
\cmidrule(lr){4-5}

&
\multicolumn{1}{c}{Coefficient} &
\multicolumn{1}{c}{95\% CI}     &
\multicolumn{1}{c}{Coefficient} &
\multicolumn{1}{c}{95\% CI}     \\
\midrule

\beta_{\nm{concern}_2} & 0.190\makebox[0pt][l]{$^{\ast}$} 
                               & ( 0.113, 0.268) & 0.171 & ( 0.100, 0.241) \\
\beta_{\nm{concern}_3} & 0.117 & ( 0.043, 0.191) & 0.117 & ( 0.050, 0.183) \\ 
\beta_{\nm{concern}_4} & 0.210 & ( 0.139, 0.281) & 0.190 & ( 0.127, 0.253) \\ 
\beta_{\nm{concern}_5} & 0.204 & ( 0.135, 0.273) & 0.111 & ( 0.049, 0.173) \\  
\beta_{\nm{breath}_2}  & 0.157 & ( 0.078, 0.236) & 0.208 & ( 0.136, 0.280) \\
\beta_{\nm{breath}_3}  & 0.115 & ( 0.041, 0.189) & 0.100 & ( 0.034, 0.166) \\
\beta_{\nm{breath}_4}  & 0.236 & ( 0.160, 0.311) & 0.301 & ( 0.234, 0.368) \\  
\beta_{\nm{breath}_5}  & 0.092 & ( 0.020, 0.163) & 0.079 & ( 0.015, 0.144) \\
\beta_{\nm{weath}_2}   & 0.164 & ( 0.092, 0.236) & 0.137 & ( 0.071, 0.203) \\
\beta_{\nm{weath}_3}   & 0.160 & ( 0.089, 0.231) & 0.199 & ( 0.135, 0.263) \\
\beta_{\nm{weath}_4}   & 0.141 & ( 0.067, 0.215) & 0.133 & ( 0.066, 0.199) \\
\beta_{\nm{weath}_5}   & 0.176 & ( 0.103, 0.249) & 0.257 & ( 0.191, 0.323) \\ 
\beta_{\nm{sleep}_2}   & 0.111 & ( 0.036, 0.187) & 0.135 & ( 0.068, 0.203) \\ 
\beta_{\nm{sleep}_3}   & 0.110 & ( 0.036, 0.184) & 0.176 & ( 0.110, 0.242) \\   
\beta_{\nm{sleep}_4}   & 0.131 & ( 0.056, 0.205) & 0.162 & ( 0.095, 0.229) \\  
\beta_{\nm{sleep}_5}   & 0.011 & (-0.064, 0.086) & 0.034 & (-0.033, 0.101) \\ 
\beta_{\nm{act}_2}     & 0.135 & ( 0.060, 0.209) & 0.033 & (-0.033, 0.100) \\
\beta_{\nm{act}_3}     & 0.195 & ( 0.121, 0.269) & 0.203 & ( 0.137, 0.268) \\  
\beta_{\nm{act}_4}     & 0.214 & ( 0.139, 0.290) & 0.254 & ( 0.186, 0.321) \\ 
\beta_{\nm{act}_5}     & 0.224 & ( 0.154, 0.294) & 0.158 & ( 0.095, 0.221) \\

\midrule[\heavyrulewidth]
\multicolumn{5}{l}{\footnotesize$^*$ statistically significant at 5\% level} \\
\bottomrule
\end{tabular}
\caption{Regression Coefficients of model 1 and model 2}\label{beta}
\end{table}



\end{document}

I've made some notable changes.

  1. The subscripts are upright, being words

  2. The alignment is improved by using features of the table itself; for instance, the third and fifth column are right aligned because of the minus signs only in the first coordinate; it wouldn't be so if the minus sign appeared also in the second coordinate or the headers had been wider.

  3. With \cmidrule it's easier to show how the headers group the columns.

  4. A trick is used for avoiding the * to take up space.

  5. An array trick is used for setting all columns in math mode, ensuring that the minus signs are printed as such.

  6. \centering is used instead of the center environment (that adds vertical space).

enter image description here

If you need to change "95% CI" to "95% Bayesian Interval", the best is to split the long phrase into two lines: modify the block

\multicolumn{1}{c}{Coefficient} &
\multicolumn{1}{c}{95\% CI}     &
\multicolumn{1}{c}{Coefficient} &
\multicolumn{1}{c}{95\% CI}     \\
\midrule

into

\multicolumn{1}{c}{Coefficient} & \multicolumn{1}{c}{95\% Bayesian} &
\multicolumn{1}{c}{Coefficient} & \multicolumn{1}{c}{95\% Bayesian} \\
                                & Interval                          &
                                & Interval                          \\
\midrule
share|improve this answer
    
I would add a thin \midrule between each group of 4 lines, to increase the legibility of the table. –  yo' Jan 2 '13 at 12:39
    
@tohecz This might be a good idea; it mostly depends on the nature of the data. –  egreg Jan 2 '13 at 13:15
    
I have deleted my answer since it is just a subset of yours. :) –  hpesoj626 Jan 12 '13 at 4:19
    
@egreg, can you please do me a last favour? I will use this table for the Bayesian intervals as well. So, I exchanged "95 % CI" with "95 % Bayesian intervals". Since "95 % Bayesian intervals" is longer than "95 % CI", the plot skewed to the right. So, what I want to do is to put "intervals" just under "95 % Bayesian". Can you please edit the question for that? Thanks in advance –  Günal Jan 13 '13 at 11:12

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.