# scaling a table to fit an entire page

I used Excel2Latex to pump out some tables from my excel file. All works fine but heres the output picture:

I want the table to be streched accross the entire page. Is this possible and if so how do I do it. Here is the code I am using:

\documentclass{article}
\usepackage{bigstrut}

\begin{document}

% Table generated by Excel2LaTeX from sheet 'Sheet1'
\begin{table}[htbp]
\centering
\caption{Table shows the commulative oxygen levels at 2 minute time intervals. The displacement is measured in \textbf{cm}}
\begin{tabular}{|r|r|r|r|r|r|r|r|r|r|}
\cline{2-10}    \multicolumn{1}{r|}{} & \multicolumn{9}{c|}{\textbf{Time of reading (in min)}}   \\
\cline{2-10}    \multicolumn{1}{r|}{} & \multicolumn{1}{r}{\textbf{0}} & \multicolumn{1}{r}{\textbf{2}} & \multicolumn{1}{r}{\textbf{4}} & \multicolumn{1}{r}{\textbf{6}} & \multicolumn{1}{r}{\textbf{8}} & \multicolumn{1}{r}{\textbf{10}} & \multicolumn{1}{r}{\textbf{12}} & \multicolumn{1}{r}{\textbf{14}} & \textbf{16} \bigstrut\\
\hline
\hline
\textbf{Treatment 1} & 0     & 0     & 0.5   & 0.7   & 0.9   & 0.9   & 1     & 1.2   & 1.8 \bigstrut\\
\hline
\textbf{Treatment 2} & 0     & 0     & 0     & 0.1   & 0.1   & 0.1   & 0.1   & 0.2   & 0.5 \bigstrut\\
\hline
\textbf{Treatment 3} & 0     & 0     & 0     & 0     & 0     & 0     & 0     & 0     & 0 \bigstrut\\
\hline
\end{tabular}%
\end{table}%
\end{document}

-

To declare some predefined width for your table, you can use the tabular* environment or, even better, the tabularx environment from the tabularx package. I would also suggest you to consider some changes to the table layout: 1) Don't use vertical rules. 2) Use the features provided by the booktabs package. Here's your table with some modifications:

\documentclass{book}
\usepackage{booktabs}
\usepackage{tabularx}

\begin{document}

\begin{table}
\centering
\caption{Table shows the commulative oxygen levels at 2 minute time intervals. The displacement is measured in \textbf{cm}}
\begin{tabularx}{\textwidth}{@{}>{\bfseries}c*{9}{X}@{}}
\toprule
Treatment & \multicolumn{9}{c@{}}{\textbf{Time of reading (in min)}} \\
\cmidrule(l){2-10}
& \textbf{0} & \textbf{2} & \textbf{4} & \textbf{6} & \textbf{8} & \textbf{10} & \textbf{12}
& \textbf{14} & \textbf{16} \\
\cmidrule(r){1-1}\cmidrule(l){2-10}
1 & 0     & 0     & 0.5   & 0.7   & 0.9   & 0.9   & 1     & 1.2   & 1.8 \\
2 & 0     & 0     & 0     & 0.1   & 0.1   & 0.1   & 0.1   & 0.2   & 0.5 \\
3 & 0     & 0     & 0     & 0     & 0     & 0     & 0     & 0     & 0 \\
\bottomrule
\end{tabularx}%
\end{table}%

\end{document}


-
is it possible to get the treatment on the second line? –  masfenix Nov 24 '11 at 6:17
@masfenix Just move it there ... Put it just before & \textbf{0}. –  Torbjørn T. Nov 24 '11 at 7:43

The tabularx package provides the tabularx environment that was built just for this purpose. The first argument is the width of the table.

Here is your table in a MWE

\documentclass{report}

\usepackage{bigstrut}
\usepackage{tabularx}

\begin{document}

\begin{table}[htbp]
\centering
\caption{Table shows the commulative oxygen levels at 2 minute time intervals. The displacement is measured in \textbf{cm}}
\begin{tabularx}{\textwidth}{|r|X|X|X|X|X|X|X|X|X|}
\cline{2-10}    \multicolumn{1}{r|}{} & \multicolumn{9}{c|}{\textbf{Time of reading (in min)}}   \\
\cline{2-10}    \multicolumn{1}{r|}{} & \multicolumn{1}{r}{\textbf{0}} & \multicolumn{1}{r}{\textbf{2}} & \multicolumn{1}{r}{\textbf{4}} & \multicolumn{1}{r}{\textbf{6}} & \multicolumn{1}{r}{\textbf{8}} & \multicolumn{1}{r}{\textbf{10}} & \multicolumn{1}{r}{\textbf{12}} & \multicolumn{1}{r}{\textbf{14}} & \textbf{16} \bigstrut\\
\hline
\hline
\textbf{Treatment 1} & 0     & 0     & 0.5   & 0.7   & 0.9   & 0.9   & 1     & 1.2   & 1.8 \bigstrut\\
\hline
\textbf{Treatment 2} & 0     & 0     & 0     & 0.1   & 0.1   & 0.1   & 0.1   & 0.2   & 0.5 \bigstrut\\
\hline
\textbf{Treatment 3} & 0     & 0     & 0     & 0     & 0     & 0     & 0     & 0     & 0 \bigstrut\\
\hline
\end{tabularx}%
\end{table}%

\end{document}

-
Thankyou! Its very helpful –  masfenix Nov 24 '11 at 2:27

You could use the tabular* environment instead of the tabular environment. The tabular* environment takes an extra argument, which you should set to \textwidth. Inside the environment's second argument, use the construct @\extracolsep{\fill}} to indicate that all intercolumn spaces should be augmented by \fill, which will make the entire environment take up the width of \textwidth.

I've taken the liberty of streamlining your code a bit in the following MWE. For instance, I've defined the contents of the first column to be typeset in bold automatically, saving some coding later on. The many \multicolumn commands in the table's second row aren't necessary, by the way. I've also dispensed with the vertical rules, as I believe they don't add appreciably to the table's intelligibility. Finally, I've used the commands \toprule, \cmidrule, \midrule, and \bottomrule of the booktabs package to get some well-spaced horizonal rules (in lieu of using \hline).

\documentclass{article}
\usepackage{array,booktabs}
\begin{document}
\begin{table}[h]
\caption{Table shows the commulative oxygen levels at 2 minute time intervals.
The displacement is measured in \textbf{cm}}  \label{tab:addlabel}
\begin{tabular*}{\textwidth}{@{}>{\bfseries}l@{\extracolsep{\fill}}*{9}{l}@{}}
\toprule
& \multicolumn{9}{c}{\textbf{Time of reading (in min)}}   \\
\cmidrule{2-10}
& \textbf{0} & \textbf{2} & \textbf{4} & \textbf{6}  & \textbf{8}
& \textbf{10} & \textbf{12} & \textbf{14} & \textbf{16} \\
\midrule
Treatment 1 & 0{\phantom{.0}} & 0{\phantom{.0}} & 0.5 & 0.7 & 0.9 & 0.9
& 1 & 1.2 & 1.8 \\
Treatment 2 & 0   & 0  & 0   & 0.1 & 0.1 & 0.1 & 0.1 & 0.2 & 0.5 \\
Treatment 3 & 0   & 0  & 0   & 0   & 0   & 0   & 0   & 0   & 0   \\
\bottomrule
\end{tabular*}
\end{table}
\end{document}


-
Hey I've copied and pasted that exact code 4 times. However on the 4th table it moves on to a new page (centered in the middle) How do I force them all to be on the same page? –  masfenix Nov 24 '11 at 9:16
Hmm, sounds like you need to save some (vertical) space somewhere, or else temporarily enlarge the textblock (for the current page). How large is your page (a4? letter?). If you're missing at most a few millimeters in order to squeeze in the fourth table, you could try issuing the command \enlargethispage{1.5\baselineskip} and rerun latex. If this won't get you all four tables on the same page, you could type \small before each of the \begin{tabular*}... commands; this will reduce the size of the font by 1pt -- not perfect, but generally not too noticeable either.Let me know if it works. –  Mico Nov 24 '11 at 12:01
@masfenix: An additional idea: On the fourth table, change the [h] affis to [t] -- this won't force the fourth table to fit on the same page as the first three, but at least it'll be placed at the top of the second page. –  Mico Nov 24 '11 at 13:46