5

Okay, I know there are a few questions already about this but I looked at them and tried to get it to work but couldn't, I'm kinda new at this so I dont really have a clue what I'm doing. Anyway here's whats wrong. I want to get a single long header across my columns like this :

_______________________________
             Dataset A
_______________________________
1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 |   

This is the code I have

\begin{table}[h]
     \begin{tabular}{|c|c|c|c|c|c|c|c|}
     \multicolumn{8}{c}{Dataset A} \\
 L (m) & T (s) & T$^2$ (s$^2$) & L$^{1/2}$ (m$^{1/2}$) & $\Delta$T$^2$ (s$^2$) & $\Delta$T (s) & Fitted T$^2$ (s$^2$)  & Fitted T (s) \\ \hline
    0.2 & 0.626 & 0.392 & 0.447 & 0.006 & 0.005 & 0.394 & 0.662 \\ 
    0.3 & 0.889 & 0.790 & 0.548 & 0.009 & 0.005 & 0.797 & 0.889 \\ 
    0.4 & 1.105 & 1.221 & 0.632 & 0.011 & 0.005 & 1.201 & 1.081 \\ 
    0.5 & 1.261 & 1.590 & 0.707 & 0.013 & 0.005 & 1.604 & 1.250 \\ 
    0.6 & 1.420 & 2.016 & 0.775 & 0.014 & 0.005 & 2.008 & 1.403 \\ 
    0.7 & 1.555 & 2.418 & 0.837 & 0.016 & 0.005 & 2.411 & 1.543 \\ 
    0.8 & 1.679 & 2.819 & 0.894 & 0.017 & 0.005 & 2.814 & 1.674 \\ 
    0.9 & 1.798 & 3.233 & 0.949 & 0.018 & 0.005 & 3.218 & 1.797 \\ 
    1.0 & 1.901 & 3.614 & 1.000 & 0.019 & 0.005 & 3.621 & 1.913 \\ 
    1.1 & 2.000 & 4.000 & 1.049 & 0.020 & 0.005 & 4.025 & 2.023 \\
\end{tabular}
\end{table}

I cant figure out why this wont work, So if anyone could help me I'd really appreciate it. It works fine if I remove the multicolumn line and just typeset it without the heading. Anyway any help would be massively appreciated. Thanks,

David Carlisle
  • 757,742

1 Answers1

4

You could place \hline at the end of the first and last line. You could use the column format |c| in the multicolumn. Setting \renewcommand{\arraystretch}{3} or some other more appropriate value can get the horizontal rules not to squeeze the lines too much.

\documentclass{article}
\pagestyle{empty}
\begin{document}
\begin{table}[h]
     \begin{tabular}{|c|c|c|c|c|c|c|c|}\hline
     \multicolumn{8}{|c|}{Dataset A} \\\hline
 L (m)  & T (s) & T$^2$ (s$^2$) & L$^{1/2}$ (m$^{1/2}$) & $\Delta$T$^2$ (s$^2$) & $\Delta$T (s) & Fitted T$^2$ (s$^2$) & Fitted T (s) \\ \hline
    0.2 & 0.626 & 0.392         & 0.447                 & 0.006                 & 0.005         & 0.394                & 0.662 \\ 
    0.3 & 0.889 & 0.790         & 0.548                 & 0.009                 & 0.005         & 0.797                & 0.889 \\ 
    0.4 & 1.105 & 1.221         & 0.632                 & 0.011                 & 0.005         & 1.201                & 1.081 \\ 
    0.5 & 1.261 & 1.590         & 0.707                 & 0.013                 & 0.005         & 1.604                & 1.250 \\ 
    0.6 & 1.420 & 2.016         & 0.775                 & 0.014                 & 0.005         & 2.008                & 1.403 \\ 
    0.7 & 1.555 & 2.418         & 0.837                 & 0.016                 & 0.005         & 2.411                & 1.543 \\ 
    0.8 & 1.679 & 2.819         & 0.894                 & 0.017                 & 0.005         & 2.814                & 1.674 \\ 
    0.9 & 1.798 & 3.233         & 0.949                 & 0.018                 & 0.005         & 3.218                & 1.797 \\ 
    1.0 & 1.901 & 3.614         & 1.000                 & 0.019                 & 0.005         & 3.621                & 1.913 \\ 
    1.1 & 2.000 & 4.000         & 1.049                 & 0.020                 & 0.005         & 4.025                & 2.023 \\\hline
\end{tabular}
\end{table}

\end{document}

enter image description here

Here's an example where the \arraystretch has been set to 1.5:

enter image description here

A.Ellett
  • 50,533
  • Thanks so much! that worked perfectly, still not sure where mine was wrong exactly but yours worked great. Thanks, – bigbadpiano Dec 06 '12 at 23:34