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 used Excel2Latex to pump out some tables from my excel file. All works fine but heres the output picture:

table 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}%
  \label{tab:addlabel}%
\end{table}%
\end{document}
share|improve this question
    
See also this post –  cmhughes Nov 24 '11 at 3:42
add comment

4 Answers

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}%
  \label{tab:addlabel}%
\end{table}%

\end{document}

enter image description here

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

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

screenshot

\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}%
  \label{tab:addlabel}%
\end{table}%



\end{document}
share|improve this answer
    
Thankyou! Its very helpful –  masfenix Nov 24 '11 at 2:27
add comment

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}

enter image description here

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

I am writing a report and facing similar problem. I want to included a long table (spreading over many pages) in the appendix of the report. The tale contains around 100 columns but only four rows. I want to include maximum columns in a page. I am using the following latex command line. I would be grateful for a favorable consideration.

\begin{landscape}
\setlength\LTleft{2pt} \setlength\LTright{2pt}
\begin{table}[htbp] \caption*{}
\begin{longtable}{|l|p{4in}|l|p{4in}|}\hline
HS2&Description&HS2&Description \\ \hline
01&Live animals&20&Vegetable, fruit, nut, etc food preparations \\
\hline 02&Meat and edible meat offal&21&Miscellaneous edible
preparations \\ \hline 03&Fish, crustaceans, molluscs, aquatic
invertebrates nes&22&Beverages, spirits and vinegar \\ \hline
04&Dairy products, eggs, honey, edible animal product
nes&23&Residues, wastes of food industry, animal fodder \\ \hline
...
....
(up to 100 times)
\end{longtable}
\end{table}
\end{landscape}
share|improve this answer
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.