# excel2latex table: output out of page

I generated the following code for a table using excel2latex add-in. However in the PDF output the table is ugly and morely cut halfway and moves to the right. Please suggest a solution.

% Table generated by Excel2LaTeX from sheet 'Sheet4'
\begin{table}[htbp]
\centering
\begin{tabular}{rrrr}
\toprule
\multicolumn{1}{c}{Question 5} & \multicolumn{1}{c}{ATT} & \multicolumn{1}{c}{ATNT} & ATE \\
\midrule
&       &       &  \\
(a) True treatment parameters & 0.471 & 0.315 & 0.365866 \\
&       &       &  \\
(b) Kernel matching estimate & 0.546 & 0.394 & 0.443377 \\
(Variability of estimation of pscores not taken into account) &       &       &  \\
&       &       &  \\
(c) Nearest-neighbour matching estimates & 0.448 & 0.375 & 0.398856 \\
&       &       &  \\
(d) Treatment estimates using OLS & 0.489096 & 0.489096 & 0.489096 \\
Homogenous returns on trimmed data and specification of pscores as in Q 1 (b) &       &       &  \\
&       &       &  \\
(e) Treatment estimates using Linear Regression & 0.587089 & 0.378109 & 0.44625 \\
&       &       &  \\
(f) Treatment estimates using Re-weighting & 0.556587 & 0.417025 & 0.462531 \\
\bottomrule
\end{tabular}%
\end{table}%

-

The easiest way to make this table fit within your page margins is to use tabularx. That requires you to use a tabularx environment (instead of tabular) and specify a width of the table (\linewidth would stretch the entire text block width).

Here's your table, wrapped in a minimal working example (uncomment the showframe package to see the text block boundaries):

\documentclass{article}
%\usepackage{showframe}% http://ctan.org/pkg/showframe
\usepackage{booktabs}% http://ctan.org/pkg/booktabs
\usepackage{array}% http://ctan.org/pkg/array
\usepackage{tabularx}% http://ctan.org/pkg/tabularx
\begin{document}

% Table generated by Excel2LaTeX from sheet 'Sheet4'
\begin{table}[htbp]
\centering
\begin{tabularx}{\textwidth}{>{\raggedleft\arraybackslash}Xrrr}
\toprule
\multicolumn{1}{c}{Question 5} & \multicolumn{1}{c}{ATT} & \multicolumn{1}{c}{ATNT} & ATE \\
\midrule
&       &       &  \\
(a) True treatment parameters & 0.471 & 0.315 & 0.365866 \\
&       &       &  \\
(b) Kernel matching estimate & 0.546 & 0.394 & 0.443377 \\
(Variability of estimation of pscores not taken into account) &       &       &  \\
&       &       &  \\
(c) Nearest-neighbour matching estimates & 0.448 & 0.375 & 0.398856 \\
&       &       &  \\
(d) Treatment estimates using OLS & 0.489096 & 0.489096 & 0.489096 \\
Homogenous returns on trimmed data and specification of pscores as in Q 1 (b) &       &       &  \\
&       &       &  \\
(e) Treatment estimates using Linear Regression & 0.587089 & 0.378109 & 0.44625 \\
&       &       &  \\
(f) Treatment estimates using Re-weighting & 0.556587 & 0.417025 & 0.462531 \\
\bottomrule
\end{tabularx}%
\end{table}%
\end{document}


tabularx provides an X column type that fills the remainder of the text block as is needed to fill to the width specified in the second argument to tabularx. The array package notation allows you to insert stuff before each X-column entry: >{\raggedleft\arraybackslash} allows for flush right/ragged left alignment, while \arraybackslash restores the traditional use of \\ for a tabular new line.

If you're not interested in tabularx, you could also just use

\begin{tabular}{>{\raggedleft\arraybackslash}p{.5\linewidth}rrr}
%...
\end{tabular}%


Here a p{<len>} column creates a paragraph-style column of width <len>, thereby forcing entries to wrap if necessary. This allows you to shrink the width of the table according to your liking.

-
Thanks Werner, and sorry for the delayed response. –  Abhimanyu Arora May 19 '12 at 12:29

The first cell of each row is always the same size. You have very long text in this first cell, at least in some rows. One possible solution would be to make these rows multicolums, see example below. Anyway, if you want a nicer table, you will have to re-arrange something.

\begin{table}[htbp]
\centering
\begin{tabular}{lrrr}
\toprule
\multicolumn{1}{c}{Question 5} & \multicolumn{1}{c}{ATT} & \multicolumn{1}{c}{ATNT} & ATE    \\
\midrule
&       &       &  \\
(a) True treatment parameters & 0.471 & 0.315 & 0.365866 \\
&       &       &  \\
(b) Kernel matching estimate & 0.546 & 0.394 & 0.443377 \\
\multicolumn{4}{l}{(Variability of estimation of pscores not taken into account)}  \\
&       &       &  \\
(c) Nearest-neighbour matching estimates & 0.448 & 0.375 & 0.398856 \\
&       &       &  \\
(d) Treatment estimates using OLS & 0.489096 & 0.489096 & 0.489096 \\
\multicolumn{4}{l}{Homogenous returns on trimmed data and specification of pscores as in    Q 1 (b)} \\
&       &       &  \\
(e) Treatment estimates using Linear Regression & 0.587089 & 0.378109 & 0.44625 \\
&       &       &  \\
(f) Treatment estimates using Re-weighting & 0.556587 & 0.417025 & 0.462531 \\
\bottomrule
\end{tabular}%